0

我正在尝试根据浏览器类型分配主题。我想在基类中执行此操作,因此它只需要在一个地方(我正在使用母版页)。我编写了以下代码,但这里的“OnLoad”是在“Page_PreInit”之前执行的。这需要进入 Page_PreInit,但为什么不触发呢?

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

然后,我将登录页面编码为继承基类:

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

谢谢你,詹姆斯

4

1 回答 1

1

您需要在基类中覆盖。 OnPreInit

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

有关使用自定义基类的更多信息,请参见此处

于 2009-09-30T02:22:40.950 回答