473,322 Members | 1,401 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,322 software developers and data experts.

Run code for every Page_Load?

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
Nov 19 '05 #1
5 1701
You run it in Application_Start or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
el********@hotmail.com
-----Original Message-----
I would like some common code to be executed before Page_Load is called forevery Web Form page. The code should do some logging.

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

Olav
.

Nov 19 '05 #2
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

"Elton Wang" <an*******@discussions.microsoft.com> wrote in message
news:1e****************************@phx.gbl...
You run it in Application_Start or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
el********@hotmail.com
-----Original Message-----
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
.

Nov 19 '05 #3
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

"Olav Tollefsen" <x@y.com> wrote in message
news:uA**************@TK2MSFTNGP10.phx.gbl...
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

"Elton Wang" <an*******@discussions.microsoft.com> wrote in message
news:1e****************************@phx.gbl...
You run it in Application_Start or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
el********@hotmail.com
-----Original Message-----
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
.


Nov 19 '05 #4
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.

"Olav Tollefsen" <x@y.com> wrote in message
news:uA**************@TK2MSFTNGP10.phx.gbl...
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

"Elton Wang" <an*******@discussions.microsoft.com> wrote in message
news:1e****************************@phx.gbl...
You run it in Application_Start or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
el********@hotmail.com
-----Original Message-----
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
.


Nov 19 '05 #5
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

"Olav Tollefsen" wrote:
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

Nov 19 '05 #6

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

Similar topics

7
by: Studio P.M. | last post by:
Dear colleagues, Does anyone have an idea where I could find precise and detailed explanation of each and every statement of the following “Web Form Designer generated code”: #region Web...
2
by: Mark Harris | last post by:
I have an interesting situation that i could not find a resolution for on google or msdn, it goes as follows: The web app i have has about 35 pages, each requires the same code in the page_load...
10
by: Daves | last post by:
Is there any way to have a custom server control for all aspx pages which runs code before the page_load event? I need some code to be run before the page_load since it's supposed to change some...
4
by: Jeff Lynch | last post by:
I need to call a class on every web page in a site. In ASP.NET 1.1 I would call this class before the Page_Load event in each web page's code-behind file since it needs to run before the web page...
4
by: Peter Bons | last post by:
Hi all, I have an asp.net page with a button that has a javascript onclick method attached to it to display a modal dialog like this: If reportHasParameters Then 'add client side onclick()...
2
by: Jay | last post by:
Is it possible to use the <% %> tag to embed a variable from page_load into a meta tag in the aspx source? Somehow I am not getting the value out of my variable properly - probably not using...
4
by: -D- | last post by:
I'm new to .net and just learning c#. I have the following code in vb and want to convert this to c# Public Class PositionData Private strText As String Private strUrl As String Public...
3
by: Bart Van Hemelen | last post by:
I'm working on a project where the user of a site will receive custom content, depending on a set of parameters. The content will all be contained in UserControls (.ascx), that will be used as...
3
by: David C | last post by:
Can someone tell me if the code in the Page_Load sub runs every time...even on PostBack? If so, what is the difference between the Page_Load and the <% %code at the top of an aspx page? Thanks. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.