Ray-
Yeah, I've used the technique of creating a common base class before. It
works well, but still requires a change to every page, albiet once. I was
hoping there might be some way to hook into the page's events without having
to edit the page itself - similar to how a HttpModule can hook into the Http
pipeline's events.
Thanks-
Eric
"Ray Booysen" wrote:
Eric Marthinsen wrote:
Hello-
I need to run some code on every one of my ASP.NET pages (1.x). The code
basically registers some client script blocks. I've been trying to find a way
to do this that doesn't involve me creating a new base class for all of my
pages. I was hoping that I could hook into an event via the Global.asax of an
HttpModule, but alas, I need to get at the Page object to register the
scripts. Does anyone have any ideas?
Regards-
Eric
The simplest would just to create one base class for all your pages, not
many.
public class BasePage : System.Web.Page
{
public void RegisterScripts()
{
//Do Work Here
}
}
Then your pages can just inherit from this page
public class MyScreen : BasePage
{
public void Page_Load()
{
this.RegisterScripts();
}
}
And you're done! :)