如何使用母版页在基类中分配主题?

发布于 2024-08-06 02:54:26 字数 854 浏览 4 评论 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

谢谢, 詹姆斯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一笑 2024-08-13 02:54:26

您需要重写基类中的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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文