473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Applying Processing to Every Page

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
Jul 15 '06 #1
2 1135
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! :)
Jul 15 '06 #2
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! :)
Jul 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Henry Hartley | last post by:
I've got a PHP system working on a development server (Windows 2000/IIS5/PHP 4.3.3) but it doesn't seem to be working quite right on the testing server (same except PHP 4.2.3). I upgraded the PHP...
11
by: The Bicycling Guitarist | last post by:
Oh lords and ladies of ciwah, I have already been told by one person that the <h1> on my home page doesn't look like proper semantic markup to them. That person suggested a <p> with style by CSS....
3
by: bdwise | last post by:
I generate a querystring on page #1 and want that querystring to stay on every other page the user chooses, regardless of session or postback issues. What is a good way to handle that? Thanks.
1
by: MattB | last post by:
I'd like to preface every page in my application's title with some text. I have what I think is a good idea on how to do this, but I'm not sure how to refer to the current page from...
3
by: Ron James | last post by:
I would like to add a CSS link to every page on my site - "<LINK href="BLT.css" type="text/css" rel="stylesheet">". This links needs to go in the <HEAD> of my page. I was hoping that I could...
0
by: HackingPSP | last post by:
I saw a lot of requests for a program like this, so I wrote it. Yeah, my site has "PSP software by Auri" but in this case it means "Pretty Sweet Programming" :) There's both a VS2005 add-in and a...
3
by: JackBlack | last post by:
Hi, all! Using ASP.Net (2.0 framework) with VB.Net code-behind... Is there any way to execute a particular piece of code on each and every page load in a website, without specifically putting...
2
by: GD | last post by:
I have an ASP .Net 1.1 app where I am trying to store some values in a session object. The problem I am encountering is that the Session appears to restart for every page loaded and also for every...
1
by: Don Habibi | last post by:
Working in Visual Studio 2010 and ASP 4.0. Getting a Session Start on every page load and all session data is lost. Switched to cookies and same thing all data is lost when switching from page to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.