calling class method

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
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.
 
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
 
Back
Top