Applying Processing to Every Page

G

Guest

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
 
R

Ray Booysen

Eric said:
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! :)
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,081
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top