H
hamstak
I had developed a custom base page class for the 1.1 framework which I
have now migrated to the 2.0 framework. I discovered that the new
partial class system -- which appears to "automagically" assign the
Page_Load method as the Load event handler in the hidden partial class
-- does not carry over to derived Page classes. This being the case,
and not wanting to copy what used to be the VS generated code into
every derived page, I decided to attempt to assign the Load event
handler in the custom base class.
This is what I came up with:
/// Custom base class ////////////////////////////////////////
protected class BasePage : System.Web.UI.Page
{
// ctor, other code implied
override protected void OnInit(EventArgs e)
{
this.Load += new System.EventHandler(this.Page_Load);
base.OnInit(e);
}
virtual protected void Page_Load
{
// no code defined
}
} // end class
/// Derived class /////////////////////////////////////////
public class MyPage : BasePage
{
// ctor, other code implied
override protected Page_Load(object sender, EventArgs e)
{
// some code
base.PageLoad(sender,e);
}
} // end class
//////////////////////////////////////////////////////////////
This seems to work like a charm. If anyone has any comments on why
this is a less-than-preferable technique, suggestions for improvement,
or a more elegant solution I would be glad to hear them!
Tom
Mnemoweb Incorporated
have now migrated to the 2.0 framework. I discovered that the new
partial class system -- which appears to "automagically" assign the
Page_Load method as the Load event handler in the hidden partial class
-- does not carry over to derived Page classes. This being the case,
and not wanting to copy what used to be the VS generated code into
every derived page, I decided to attempt to assign the Load event
handler in the custom base class.
This is what I came up with:
/// Custom base class ////////////////////////////////////////
protected class BasePage : System.Web.UI.Page
{
// ctor, other code implied
override protected void OnInit(EventArgs e)
{
this.Load += new System.EventHandler(this.Page_Load);
base.OnInit(e);
}
virtual protected void Page_Load
{
// no code defined
}
} // end class
/// Derived class /////////////////////////////////////////
public class MyPage : BasePage
{
// ctor, other code implied
override protected Page_Load(object sender, EventArgs e)
{
// some code
base.PageLoad(sender,e);
}
} // end class
//////////////////////////////////////////////////////////////
This seems to work like a charm. If anyone has any comments on why
this is a less-than-preferable technique, suggestions for improvement,
or a more elegant solution I would be glad to hear them!
Tom
Mnemoweb Incorporated