calling class method

G

Guest

I am trying to create instance of class and and call a method of this class
that creates a global variable which is available in anywhere in the page..

Here is what i am doing.. but i am getting build error message as shown:

C:\Inetpub\aspnet\intranet\bs\request.aspx.cs(45):
'intranet.departments.building_services.request.NTSecurity' denotes a 'field'
where a 'class' was expected

The line in question is:
protected string LogonUser = NTSecurity.getLogonUser();

Basically i want to access this variable from any mothods inside the page
without keeping calling this line of code in every methods.

public class request : System.Web.UI.Page
{
protected security NTSecurity = new security();
protected string LogonUser = NTSecurity.getLogonUser();
private void Page_Load(object sender, System.EventArgs e)
{

}

any suggestion how? many thanks in advance
 
G

Guest

hi

if you want to create an instace use this constructor for your class.
public static readonly Application Instance = new Application();
and access this like Application.Instance.Method.

Cheers
 
G

Guest

You say you want a class which is available globally .
I think you want a custom page but i didn't understand from first time your
question. So Create a custom page and there you can put session variables and
also global variable if you need this in every page. And then derive all of
your pages from that page.
 
E

Enrique Santa Cruz

If you declare your variable in the page class you will lose the value every
time the page is called so it will not be a global variable.
You should instead use a Session object if you want the variable available
for each session or an Application object if you want it available for the
lifetime of the Application all sessions that is.

Enrique.
 
G

Guest

i want the variable to be available in that page only, i don't want to make
it application variable or session variable..

Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top