Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Is there Page_PreInit, but for the entire application?

Reply
Thread Tools

Is there Page_PreInit, but for the entire application?

 
 
Edward
Guest
Posts: n/a
 
      10-17-2006
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


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      10-17-2006
"Edward" <> wrote in message
news:lZ2Zg.48718$...

> 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.


 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      10-17-2006
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" <> wrote in message
news:...
> "Edward" <> wrote in message
> news:lZ2Zg.48718$...
>
>> 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.
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      10-17-2006
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:...

> 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...


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      10-17-2006
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" <> wrote in message
news:lZ2Zg.48718$...
> 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
>
>



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      10-17-2006
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" <> wrote in message news:et$...
> "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message
> news:...
>
>> 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...
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      10-17-2006
"Juan T. Llibre" <> wrote in message
news:eD%...

>I sent in a suggestion before I read both of yours


I believe you...


 
Reply With Quote
 
Edward
Guest
Posts: n/a
 
      10-17-2006
great! ... so many options to digest!

thanks everyone for your contribution


"Edward" <> wrote in message
news:lZ2Zg.48718$...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning .Net : Select entire month or entire week using selectionmode in calendar control with C# Examples and VB.Net Examples jayeshsorathia@gmail.com ASP .Net 0 09-26-2012 07:17 AM
Is there a way to make an entire HTML document linkable? mic123@gmail.com HTML 1 12-03-2007 09:44 PM
Is there a way to make an entire HTML document linkable? mic123@gmail.com HTML 1 12-03-2007 07:47 PM
how to download entire web site but exclude external links code_wrong HTML 2 08-22-2005 07:22 PM
Is there a method to fetch the last value stored in a DB column with out having to read in the entire column? DeWitt Phillips ASP .Net 2 12-12-2003 11:29 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57