Reputation: 2938
class a : System.UI.Page {
int ab= c;
}
class b : a
{
public int c= 0;
}
I cant access it. I can access any control on the page by Control.NamingContainer Property in asp.net but i have to access public variable from the class(i.e. class a) that is in form(i.e. class b) so that i doesn't have write a particular method in 50 of my form.
Upvotes: 0
Views: 3921
Reputation: 24666
I think you are using inheritance in the wrong way. Try this, it should work:
public class a : b {
int ab = c;
}
public class b : System.UI.Page
{
public int c = 0;
}
Upvotes: 0
Reputation: 2691
You could put the variable on the base class so that the inherited classes will have access to it. For example:
class a : System.UI.Page
{
protected int c = 0;
}
class b : a
{
protected void DoSomething()
{
c = 1; //Access c from derived class.
}
}
Also, if this property is not instance specific, you can always use a static property in the Global.asax file that can be accessed from anywhere within your ASP.NET application. If it is session specific, you can simply have the property access the session and store/retrieve the value from there so that each user session has their own value.
Hope this helps!
Upvotes: 2