【发布时间】:2010-10-04 08:34:08
【问题描述】:
我正在使用母版页,但无法从 @ Page 指令设置页面标题。我所有的类都继承自一个类 myPage,该类继承自 ASP.NET System.Web.UI.Page 类。 请注意:我在母版页的头部标签中设置了 runat="server"。
这是我的 @ Page 指令对于文件 test.aspx.vb 的样子:
<%@ Page language="VB" MasterPageFile="~/MainMaster.master"
autoeventwireup="false" CodeFile="test.aspx.vb"
Inherits="test" Title="test" %>
这是 test.aspx.vb 的样子:
Partial Class test
Inherits myPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
这是我的主文件 MainMaster.master 的样子:
<%@ Master Language="VB" CodeFile="MainMaster.master.vb" Inherits="MainMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>untitled</title>
</head>
...
现在,当您在浏览器中查看 test.aspx 时,您会看到标题“test”。但相反,您将根据母版页看到“无标题”。通过反复试验,我将 test 类修改为直接从 System.Web.UI.Page 继承,而不是像这样的 myPage:
Partial Class test
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
一切正常。为什么我的页面是 myPage 而不是 System.Web.UI.Page 的子页面会阻止在 @Page 指令中正确设置标题?
我意识到我可以通过每个页面中的 Page_Load 方法以编程方式设置页面标题,但我宁愿在 .aspx 文件中的 @Page 指令中进行设置。
这是一个非常奇怪和令人沮丧的问题,我很茫然!
谢谢!!!
【问题讨论】:
标签: asp.net vb.net master-pages