ASP.Net: execute function on every page loaded?

J

JackBlack

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 that same code (or user
control) on each and every page? Some languages have a config file (like
application.cfm for Cold Fusion) that loads on every page where one can run
basic code on each page load, without adding code to each page.

Is there such a beastie with ASP.Net? I know that global.asax won't do the
trick...

Thanks for any suggestions!
Jack
 
P

Patrice

Global.Asax do have a beginrrequest event ? You could also inherit from a
base page ? An httpModule ?

As John said, it's often more efficient to explain what you want to do. It
allows peers to give better advices (and perhaps sometimes a new approach to
the same problem).
 
J

Jason Kester

JackBlack said:
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 that same code (or user
control) on each and every page?

Sure. You'll probably want to derive your own custom Page object, and
have all your pages use that as their base class.

So, step one is to create a new class called MyPage or whatever, based
on System.Web.UI.Page. Override the Page_Load method there to run your
common code, or create your own protected Initialize method that you'll
call from every page that needs it.

Next, base your codebehind classes off of MyPage rather than
System.Web.UI.Page. Problem solved.

Good luck!

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 

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
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top