如何使用母版页在基类中分配主题?
我正在尝试根据浏览器类型分配主题。我想在基类中执行此操作,因此它只需要位于一个位置(我正在使用母版页)。我编写了以下代码,但此处的“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要重写基类中的
OnPreInit
。请参阅此处有关使用自定义基类的更多信息。
You need to override
OnPreInit
in the base class.See here for more information on using a custom base class.