M
ma
Hello,
I want to create a global class. To do this I did the followings:
1- Create a class name test. It has a public variable named mystring.
public class test
{
public string mystring = "hello world";
}
2- Create a global.asax and its coresponding global.asax.cs ( i did it using
VC2005)
3 - in global class generated by VC2005, I introduced test class as follow:
public class Global : System.Web.HttpApplication
{
public test myclass;
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
now I want to use it in an event in a mater page.
I did this:
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Application.myclass.mystring);
}
}
but I am getting this error:
Error 1 'System.Web.HttpApplicationState' does not contain a definition for
'myclass'
I do this:
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Global.myclass.mystring);
}
}
Error 1 An object reference is required for the nonstatic field, method, or
property 'Global.myclass'
What is wrong wioth my code?
Regards
I want to create a global class. To do this I did the followings:
1- Create a class name test. It has a public variable named mystring.
public class test
{
public string mystring = "hello world";
}
2- Create a global.asax and its coresponding global.asax.cs ( i did it using
VC2005)
3 - in global class generated by VC2005, I introduced test class as follow:
public class Global : System.Web.HttpApplication
{
public test myclass;
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
now I want to use it in an event in a mater page.
I did this:
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Application.myclass.mystring);
}
}
but I am getting this error:
Error 1 'System.Web.HttpApplicationState' does not contain a definition for
'myclass'
I do this:
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Global.myclass.mystring);
}
}
Error 1 An object reference is required for the nonstatic field, method, or
property 'Global.myclass'
What is wrong wioth my code?
Regards