Re: question about public function



Gee, I thought that is exactly what I said....

I indicated that a page is a class -
...while the page (class)...

And, loaded isn't really confusing at all, as I pointed out that this is
while "the page is being requested". Instances of classes are "loaded" into
the heap and assigned a pointer. While they have a pointer, they can be
accessed by your code. When the no longer have a pointer (like when the
page request is completed and the page response is loaded), they are the
GC's responsibility. They may still exist in memory (the heap) for some
period of time, but since the pointer to the object is gone, you can't get
to that particular instance of the object again.

Your last recommendation, "extract this method to a different object and use
that object from all pages" is exactly what I said, but more clearly, when I
indicated that the function could be placed inside of a class in a separate
..dll and then referenced and instantiated.

-Scott


"Laurent Bugnion [MVP]" <galasoft-lb@xxxxxxxxxx> wrote in message
news:%23Hm$bwMWHHA.496@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

Scott M. wrote:
The function is only available while that page (class) is loaded, which
is only while the page is being requested.

Actually, a Page is an object like any other. "loaded" is a bit confusing
in this context.

When the request arrives, an instance of the corresponding Page is
created. The instance is disposed after the Response is sent. On the next
Request, another, brand new instance of the Page is created. This explains
why you cannot save instance variables over requests, but must resort to
Session, Cache, Application objects...

However, if you have a public method in a class deriving from Page, you
can use that method at any time simply by creating a new instance of that
Page:

MyOwnPage anInstance = new MyOwnPage();
anInstance.executeSomething();

However, I wouldn't recommend this. If you have a public method that is
used in multiple pages, extract this method to a different object and use
that object from all pages. It's all abut design ;-)

HTH,
Laurent


You could place a function like this (along with other functions you wish
to call repeatedly) in their own assembly (.dll) and then just reference
that assembly from your ASP.NET project, make an instance of the class
that contains them and run them as you need to.


"Gilbert" <gi@xxxxxxx> wrote in message
news:OsuiHxGWHHA.5108@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

In the code-behind, i have this function:

Public Function myfunction(ByVal myvar As Object) As String
dim x as string = myvar
.....
Return x
End Function

My question is: can i use this function in other aspx / code-behind
pages of my application? Or, till where is this function accessible?
thanks
Gilbert





--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch


.



Relevant Pages

  • Re: IOCP touching my OVERLAPPED after my Write has completed
    ... Anton is telling you that the memory must not be freed between ... I supposed the completion of the request is the end of the overlapped ... Once you have passed a perfectly valid pointer to some function, ... Anton Bassov ...
    (microsoft.public.win32.programmer.kernel)
  • Re: IOCP touching my OVERLAPPED after my Write has completed
    ... I supposed the completion of the request is the end of the overlapped ... I cannot mark the memory as free and put it back in my pool when the IO ... Once you have passed a perfectly valid pointer to some function, ... I have a IO request pool implemented using VirtualAlloc. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: When to check the return value of malloc
    ... void *xmalloc{ ... allocate a zero amount of memory (and *why*, precisely, would anyone want ... returned shall be either a null pointer or a unique pointer." ... convenient to "normalise" the behaviour by changing the allocation request ...
    (comp.lang.c)
  • Re: TEA Implementation
    ... The second argument should be a pointer to pointer to ... It should be the address of a pointer to char. ... compiler won't even accept it at all. ... Seems like a rather confusing way of writing ...
    (comp.lang.c)
  • Re: Cobol work?
    ... confused by C-style pointer ... There are two sets from the group "programmers": ... All members of Group A haven't used pointers or are liars. ... aren't confusing, it's the care of the person using the concepts that makes ...
    (comp.lang.cobol)