C
cmay
In reading some documents from the Patterns and Practices group, I had
a question about the example given for the Page Controller pattern.
(I have posted the code for the BasePage below)
In short, their example shows a "BasePage " class for other pages to
inherit from.
The subclasses are supposed to implement the PageLoadEvent method
(which I guess should really be abstract, but can't because asp.net
won't let you inherit from a base page that is an abstract class).
Now, my question is this. I have seen many applications where the base
page, and the inheriting pages BOTH subscribe to the Load event, w/ the
Base class's event handler firing first, and then the subclasses Load
event handler.
In execution, it would work the same as what is described here, with
the only diff being that Page Controller would be intiating the Load
event on the page, rather than ASP.NET initiating the event.
Can someone explain why this matters? I guess if you were passing some
kind of information from the Page Controller to the sub class on the
PageLoadEvent method, but if you are doing just to "kick off" an event
that is already going to be kicked off by ASP.NET, what is the point?
Thanks...
Here is the Page Controller class:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class BasePage : Page
{
protected Label eMail;
protected Label siteName;
virtual protected void PageLoadEvent(object sender, System.EventArgs e)
{}
protected void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string name = Context.User.Identity.Name;
eMail.Text = DatabaseGateway.RetrieveAddress(name);
siteName.Text = "Micro-site";
PageLoadEvent(sender, e);
}
}
}
a question about the example given for the Page Controller pattern.
(I have posted the code for the BasePage below)
In short, their example shows a "BasePage " class for other pages to
inherit from.
The subclasses are supposed to implement the PageLoadEvent method
(which I guess should really be abstract, but can't because asp.net
won't let you inherit from a base page that is an abstract class).
Now, my question is this. I have seen many applications where the base
page, and the inheriting pages BOTH subscribe to the Load event, w/ the
Base class's event handler firing first, and then the subclasses Load
event handler.
In execution, it would work the same as what is described here, with
the only diff being that Page Controller would be intiating the Load
event on the page, rather than ASP.NET initiating the event.
Can someone explain why this matters? I guess if you were passing some
kind of information from the Page Controller to the sub class on the
PageLoadEvent method, but if you are doing just to "kick off" an event
that is already going to be kicked off by ASP.NET, what is the point?
Thanks...
Here is the Page Controller class:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class BasePage : Page
{
protected Label eMail;
protected Label siteName;
virtual protected void PageLoadEvent(object sender, System.EventArgs e)
{}
protected void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string name = Context.User.Identity.Name;
eMail.Text = DatabaseGateway.RetrieveAddress(name);
siteName.Text = "Micro-site";
PageLoadEvent(sender, e);
}
}
}