views:

153

answers:

1

Hi,

I am trying to assign a theme based on browser type. I would like to do this in a base class so it would only need to be in one place (I am using a master page). I coded the following but the "OnLoad" here is performed before the "Page_PreInit". This needs to go in Page_PreInit, but why isn't it firing?

Imports Microsoft.VisualBasic

Public Class MyBaseClass
Inherits System.Web.UI.Page

Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
    'Assign the CSS Theme based on the Browser Type
    If (Request.Browser.Type = "IE8") Then
        Page.Theme = "Standard-IE8"
    Else
        Page.Theme = "Standard"
    End If
End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

    MyBase.OnLoad(e)
End Sub

End Class

Then, I have my Login page coded to inherit the base class:

Partial Class Login
'Inherits System.Web.UI.Page
Inherits MyBaseClass

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Thank you, James

+1  A: 

You need to override OnPreInit in the base class.

Protected Overrides Sub OnPreInit(ByVal e As System.EventArgs)
        'Assign the CSS Theme based on the Browser Type
        If (Request.Browser.Type = "IE8") Then
            Page.Theme = "Standard-IE8"
        Else
            Page.Theme = "Standard"
        End If
        MyBase.OnPreInit(e)
    End Sub

See here for more information on using a custom base class.

Phaedrus
That is a winner. Thanks a bunch!
James