473,791 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1715
You run it in Application_Sta rt or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
el********@hotm ail.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_Beg inRequest function in
Global.asax?

Olav

"Elton Wang" <an*******@disc ussions.microso ft.com> wrote in message
news:1e******** *************** *****@phx.gbl.. .
You run it in Application_Sta rt or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
el********@hotm ail.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_Beg inRequest 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******** ******@TK2MSFTN GP10.phx.gbl...
Thanks for the hint. I think found the answer:

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

Olav

"Elton Wang" <an*******@disc ussions.microso ft.com> wrote in message
news:1e******** *************** *****@phx.gbl.. .
You run it in Application_Sta rt or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
el********@hotm ail.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******** ******@TK2MSFTN GP10.phx.gbl...
Thanks for the hint. I think found the answer:

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

Olav

"Elton Wang" <an*******@disc ussions.microso ft.com> wrote in message
news:1e******** *************** *****@phx.gbl.. .
You run it in Application_Sta rt or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
el********@hotm ail.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
2790
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 Form Designer generated code override protected void OnInit(aS.EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer.
2
1512
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 (about 62 lines). If i need to change a single part of that code, is there a way to do it without find/replace over the whole project. As the code i wish to change (and other sections i may wish to change in the future) is also in some other parts...
10
1976
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 Page properties, something like an include file in the old classic asp days...
4
1527
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 loads. In ASP.NET 2.0 can I do the same thing by calling the class on the MasterPage's code-behind before it's Page_Load and will this run before the content page's Page_Load? -- Jeff Lynch
4
2284
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() event handler to display the popup dialog for entering parametervalues btnChangeParameters.Attributes.Add("onclick", String.Format("window.showModalDialog
2
2502
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 quotes correctly or something simple, but after a full day of trying every possible syntax under the sun, I hope someone can help. Page_Load: this.myKeywords = "keyWordOne keyWordTwo keyWordThree"; aspx source:
4
1454
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 Sub New(ByVal strDisplayText As String, ByVal strURL As String)
3
2130
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 webparts on a page. We need to add the webparts dynamically to the site, depending on the status of the user: this involves a personalisation of a travel website, so a user can be "before" a trip, "during" a trip and "after" a trip, and depending...
3
1317
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. David
0
9517
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.