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

Is there Page_PreInit, but for the entire application?

Hi All,

Would anyone know if there is an event similar to the Page_PreInit that I
can code just once, at a global initialization level, that applies to all
pages executed?

Therefore, instead of placing the code below in every page codebehind, I
could code it just once.
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreInit

If Not Request.Browser.Browser.Contains("IE") Then

Me.ClientTarget = "uplevel"

End If

End Sub
Thanks

Edward Re
Oct 17 '06 #1
7 4194
"Edward" <aR******@hotmail.comwrote in message
news:lZ*******************@news-server.bigpond.net.au...
Would anyone know if there is an event similar to the Page_PreInit that I
can code just once, at a global initialization level, that applies to all
pages executed?
There isn't.
Therefore, instead of placing the code below in every page codebehind, I
could code it just once.
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreInit

If Not Request.Browser.Browser.Contains("IE") Then

Me.ClientTarget = "uplevel"

End If

End Sub
Two main options:

1) Use MasterPages and ContentPages. However, since MasterPages don't have a
Page_PreInit event, you would need to create a base class which inherited
the Page object, create a Page_PreInit event in that, and then have your
MasterPages inherit the base class.

2) Do the above but without MasterPages i.e. create a base class with the
Page_PreInit code, and derive all your other pages from it.
Oct 17 '06 #2
The master page solution is a good one.

an HttpModule's BeginRequest might also do the trick (or you could just use
Global.asax's).

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:On**************@TK2MSFTNGP04.phx.gbl...
"Edward" <aR******@hotmail.comwrote in message
news:lZ*******************@news-server.bigpond.net.au...
>Would anyone know if there is an event similar to the Page_PreInit that I
can code just once, at a global initialization level, that applies to all
pages executed?

There isn't.
>Therefore, instead of placing the code below in every page codebehind, I
could code it just once.
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreInit

If Not Request.Browser.Browser.Contains("IE") Then

Me.ClientTarget = "uplevel"

End If

End Sub

Two main options:

1) Use MasterPages and ContentPages. However, since MasterPages don't have
a Page_PreInit event, you would need to create a base class which
inherited the Page object, create a Page_PreInit event in that, and then
have your MasterPages inherit the base class.

2) Do the above but without MasterPages i.e. create a base class with the
Page_PreInit code, and derive all your other pages from it.

Oct 17 '06 #3
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:eG**************@TK2MSFTNGP03.phx.gbl...
The master page solution is a good one.
That's the one I use.
an HttpModule's BeginRequest might also do the trick (or you could just
use Global.asax's).
Here's an article which describes this, albeit for a different purpose...
http://asp-net-whidbey.blogspot.com/...t-20-http.html

Interestingly enough, I've never actually got this to work properly - IIRC,
although the BeginRequest method does indeed fire before the PreInit method,
I never seemed to get access to the Page object at this stage...
Oct 17 '06 #4
re:
Would anyone know if there is an event similar to the Page_PreInit that I can code just once, at a
global initialization level, that applies to all pages executed?
There isn't one.
The good news is that you can build an httpmodule which will do the job for you.

See :
http://staff.develop.com/ballen/blog...c-13818fd75a56

Brock uses it to select a Theme, but you can modify the code to do what you want to do.

His sample code is at :
http://staff.develop.com/ballen/blog...hemeSample.zip

....but read his blog entry before attempting to use it.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Edward" <aR******@hotmail.comwrote in message
news:lZ*******************@news-server.bigpond.net.au...
Hi All,

Would anyone know if there is an event similar to the Page_PreInit that I can code just once, at a
global initialization level, that applies to all pages executed?

Therefore, instead of placing the code below in every page codebehind, I could code it just once.
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

If Not Request.Browser.Browser.Contains("IE") Then

Me.ClientTarget = "uplevel"

End If

End Sub
Thanks

Edward Re


Oct 17 '06 #5
I sent in a suggestion before I read both of yours, which also do the work.

Brock's sample HttpModule code also works...


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message news:et**************@TK2MSFTNGP05.phx.gbl...
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME netwrote in message
news:eG**************@TK2MSFTNGP03.phx.gbl...
>The master page solution is a good one.

That's the one I use.
>an HttpModule's BeginRequest might also do the trick (or you could just use Global.asax's).

Here's an article which describes this, albeit for a different purpose...
http://asp-net-whidbey.blogspot.com/...t-20-http.html

Interestingly enough, I've never actually got this to work properly - IIRC, although the
BeginRequest method does indeed fire before the PreInit method, I never seemed to get access to
the Page object at this stage...

Oct 17 '06 #6
great! ... so many options to digest!

thanks everyone for your contribution
"Edward" <aR******@hotmail.comwrote in message
news:lZ*******************@news-server.bigpond.net.au...
Hi All,

Would anyone know if there is an event similar to the Page_PreInit that I
can code just once, at a global initialization level, that applies to all
pages executed?

Therefore, instead of placing the code below in every page codebehind, I
could code it just once.
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreInit

If Not Request.Browser.Browser.Contains("IE") Then

Me.ClientTarget = "uplevel"

End If

End Sub
Thanks

Edward Re


Oct 17 '06 #7
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:eD****************@TK2MSFTNGP04.phx.gbl...
>I sent in a suggestion before I read both of yours
I believe you...:-)
Oct 17 '06 #8

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

Similar topics

2
by: Earl Teigrob | last post by:
I am programming ASP.NET using C#. I have been accessing static variables accross my entire application but now need to change some of the static variables that are session specific to instance...
19
by: Andy B | last post by:
Hello, Sorry for this newbish question. Briefly, my problem: ------------------ I expect the database I'm working on to reach something in the order of 12-16 Gigabytes, and I am interested...
3
by: Fred Nelson | last post by:
Hi Folks: I have a question about the Page_PreInit and Page_Load events in a web application. My question is: can I count on the Page_PreInit having completed before the Page_Load event...
9
by: Lammert | last post by:
Good morning, I create an ASP.NET 2.0 web application. The situation: 1. One masterpage where the users can select an organisation in a DropDownList. 2. Different content pages. I will get...
1
by: ad | last post by:
Hi, I have set the this.Page.Theme in a MasterPage, but it no affect. I have set break point at this line, but it never execute. void Page_PreInit(object sender, System.EventArgs args) {...
0
by: elphantasmo | last post by:
Hi, I have created a hosted AxWebBrowser control and I handle the NewWindow2 event to open new windows in my own forms. Our application accesses a JSF (Java Server Faces) backend with some...
1
by: Josh Naro | last post by:
I am writing a module that requires the entire output from a web app to perform its function. So, basically I need to be able to pull the entire output stream from the Response object. I've tried...
1
by: Finn Stampe Mikkelsen | last post by:
Hi Is there any intelligent way to similate windows function to show a map of the entire network visible to an application?? My job is this...: Picture a LAN/WLAN with 5 computers connected...
18
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.