Run code for every Page_Load?

O

Olav Tollefsen

I would like some common code to be executed before Page_Load is called for
every Web Form page. The code should do some logging.

Where can I put common code like this? I would like to avoid having to
manually insert the code on every page in my application.

Olav
 
E

Elton Wang

You run it in Application_Start or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
(e-mail address removed)
 
O

Olav Tollefsen

Thanks for the hint. I think found the answer:

I guess the correct way is to create an Application_BeginRequest function in
Global.asax?

Olav
 
O

Olav Tollefsen

I tested adding a Application_BeginRequest in Global.asax and it got called
multiple times for every load of a web page.

Is this normal?

Olav
 
P

Peter Rilling

Another alternative is to create your own page class that inherits from Page
and all your pages derive from this new class. Then you can override the
OnLoad method.
 
G

Guest

Hi Olav
create a class and put int it subMAin and put all code on it
then make this the ur start page
Hope this help
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top