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 9 1746
The function is only available while that page (class) is loaded, which is
only while the page is being requested. 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@bert.sdwrote in message
news:Os**************@TK2MSFTNGP06.phx.gbl...
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
Thanks,
What is then the meaning of 'Public'?. If the function would be 'Private',
would that change its reach?
"Scott M." <s-***@nospam.nospamschreef in bericht
news:e7*************@TK2MSFTNGP06.phx.gbl...
The function is only available while that page (class) is loaded, which is
only while the page is being requested. 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@bert.sdwrote in message
news:Os**************@TK2MSFTNGP06.phx.gbl...
>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
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@bert.sdwrote in message
news:Os**************@TK2MSFTNGP06.phx.gbl...
>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
Hi,
Gilbert wrote:
Thanks,
What is then the meaning of 'Public'?. If the function would be 'Private',
would that change its reach?
It's not about the method being public or private. It's about the Page
instance's lifecycle. Read my other post in that thread.
HTH,
Laurent
--
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
Thanks
"Laurent Bugnion [MVP]" <ga*********@bluewin.chschreef in bericht
news:%2***************@TK2MSFTNGP06.phx.gbl...
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@bert.sdwrote in message news:Os**************@TK2MSFTNGP06.phx.gbl...
>>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
I tried with 'Private' instead of 'Public' and this gives an error ("not
accessible in this context because it is 'Private")
With 'Public' or even with nothing, it works.
So, the answer on my question is:
when it's 'Private', the function is only accessible in the code-behind
page;
when 'Public' or nothing, it's also accessible from the aspx file.
Private Function myfunction(ByVal myvar As Object) As String
.....
End Function
and in the aspx file:
------------------
<asp:Literal ID="rr" runat="server" Text='<%# myfunction(Eval("field1")) %>'
/>
"Laurent Bugnion [MVP]" <ga*********@bluewin.chschreef in bericht
news:%2***************@TK2MSFTNGP06.phx.gbl...
Hi,
Gilbert wrote:
>Thanks,
What is then the meaning of 'Public'?. If the function would be 'Private', would that change its reach?
It's not about the method being public or private. It's about the Page
instance's lifecycle. Read my other post in that thread.
HTH,
Laurent
--
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
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]" <ga*********@bluewin.chwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
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@bert.sdwrote in message news:Os**************@TK2MSFTNGP06.phx.gbl...
>>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
Hi,
Scott M. wrote:
Gee, I thought that is exactly what I said....
<snipYou're right. Somehow the first time I read your post, I
misunderstood what you meant; the fault lies on my side, not yours.
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.
IMHO the class doesn't need to be placed in a separate DLL, if it's used
only by different Pages in the same web application, it can be in a
separate object, but in the same DLL.
-Scott
Friendly greetings,
Laurent
--
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
When it's private, it's only accessible inside the same class. In this
case the class is the code behind. The code beind class inherits from
the Page class, and the class that is created for the aspx file inherits
from the code behind class.
To make members of the code behind class visible to the aspx class, you
can make them public or protected. Usually they are made protected as
they don't need to be more visible than that.
Not specifying accessibility at all should make them private.
Gilbert wrote:
I tried with 'Private' instead of 'Public' and this gives an error ("not
accessible in this context because it is 'Private")
With 'Public' or even with nothing, it works.
So, the answer on my question is:
when it's 'Private', the function is only accessible in the code-behind
page;
when 'Public' or nothing, it's also accessible from the aspx file.
Private Function myfunction(ByVal myvar As Object) As String
....
End Function
and in the aspx file:
------------------
<asp:Literal ID="rr" runat="server" Text='<%# myfunction(Eval("field1")) %>'
/>
"Laurent Bugnion [MVP]" <ga*********@bluewin.chschreef in bericht
news:%2***************@TK2MSFTNGP06.phx.gbl...
>Hi,
Gilbert wrote:
>>Thanks,
What is then the meaning of 'Public'?. If the function would be 'Private', would that change its reach?
It's not about the method being public or private. It's about the Page instance's lifecycle. Read my other post in that thread.
HTH, Laurent -- 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
--
Göran Andersson
_____ http://www.guffa.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jon Slaughter |
last post by:
I have a class that is basicaly duplicated throughout several files with
only members names changing according to the class name yet with virtually
the exact same coding going on.
e.g.
class...
|
by: Kevin |
last post by:
Hi al
I have an interesting question.... I am working witha Win API this is the Function
Public Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Long, ByVal...
|
by: C Downey |
last post by:
Hello:
I have an arraylist storing some very basic objects.
The object is very basic, it has 2 properties : ID, and COUNT
Before I add an object to the arraylist, I want to check if an...
|
by: Colin McGuire |
last post by:
Hi all, when I write the class below
Private Class employee
End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display
|
by: Ken H |
last post by:
Hi I have a question about architecting solutions..
I have a part of a project which requires me to track person details (name, addresses, etc...
Should I be creating Person objects, Address...
|
by: BoloBaby |
last post by:
OK, I've managed to clarify my question (whew).
I'll show two blocks of code - one in VB6.0 and one in VB.NET. The VB6.0
code manages to execute the callback function, the VB.NET does not. The...
|
by: heltena |
last post by:
Hi,
I have this "interface" (abstract class):
class Callback
{
public:
virtual void function1() = 0;
virtual void function2(string value) = 0;
};
|
by: Bryan Parkoff |
last post by:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope....
|
by: Scott Stark |
last post by:
Hello,
I'm trying to get a better handle on OOP programming principles in VB.NET.
Forgive me if this question is sort of basic, but here's what I want to do.
I have a collection of Employee...
|
by: tshad |
last post by:
I am just getting started with events and had a couple of questions on why
they do what they do.
If you have a textbox and you want to handle an event you can just do:
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |