I am having a hard time with understanding something.
I have a base class that is derived from System.Web.UI.Page.
This is an example. It mirros what I am doing but it is not what I am doing.
The problem is when it does this it goes through both Page_Load methods two times and I don't understand why. Maybe there is a better way to accomplish what I want to do which is:
Have a base class inherited from System.Web.UI.Page. Declare a few objects here.
Always set these objects (in the Page_Load to the same thing).
Have a multiple pages that inherit the base that will have these objects and have them set from the base class.
Can someone help me understand?
Thanks
Brian
I have a base class that is derived from System.Web.UI.Page.
This is an example. It mirros what I am doing but it is not what I am doing.
Code:
public class SLBase : System.Web.UI.Page
{
private string _test;
protected virtual void Page_Load(object sender, System.EventArgs e)
{
_test = "A string";
}
}
public class MyPage : SLBase
{
protected override void Page_Load(object sender, System.EventArgs e)
{
base.Page_Load(sender, e); //set _test the same way for every page
//some more page load code here
}
}
The problem is when it does this it goes through both Page_Load methods two times and I don't understand why. Maybe there is a better way to accomplish what I want to do which is:
Have a base class inherited from System.Web.UI.Page. Declare a few objects here.
Always set these objects (in the Page_Load to the same thing).
Have a multiple pages that inherit the base that will have these objects and have them set from the base class.
Can someone help me understand?
Thanks
Brian