Joh*_*ams 9 asp.net webforms master-pages title
我已经阅读了很多关于如何做到这一点的帖子/文章,我仍然没有从内容页面获取页面标题集.我的页面渲染正常,但我无法从内容页面获取标题集(所有页面都根据母版页设置了标题).这是我的母版页的代码隐藏:
Partial Class zSEO
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Header.Title = "Dynamically set in Master page"
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)
这是母版页的其余部分:
<%@ Master Language="VB"
EnableTheming="true"
Inherits="zSEO"
CodeFile="zSEO.master.vb" %>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="container">
<div id="content">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然而,我想在网页内容页面中建立页面的价值,并将其放在我的测试内容页面中:
Public Partial Class zShowAd
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Header.Title = "Dynamically set TITLE value in the content(child) page"
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)
奇怪的是,我无法让调试器在内容页面上面的行上停止 - 只在主页面的相应行上.显然,我对此感到困惑.
我已经读过有其他方法可以做到这一点,但这似乎可以从我在Scott Mitchell的教程中阅读:动态设置ASP.NET中的页面标题.具体来说,我试图在文章中遵循这一点: "此外,如果您使用母版页,则此代码可以从母版页或使用母版页的ASP.NET页面开始工作.在这种情况下,该区域应该在母版页中定义,但ASP.NET页面仍然可以通过Page.Header访问它."
Cha*_*ell 10
所以需要发生的是这个
MasterPage.Master
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Me.Page.Title = "Dynamically set in Master page"
End Sub
Run Code Online (Sandbox Code Playgroud)
Default.aspx的
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Page.Title = "Dynamically set in ASPX page"
End Sub
Run Code Online (Sandbox Code Playgroud)
这样,您的母版页标题就会在您的内容页面标题之前设置.如果您没有从内容页面设置标题,则母版页将是默认标题.如果您确实从内容页面设置了标题,那么它将覆盖它.
| 归档时间: |
|
| 查看次数: |
14861 次 |
| 最近记录: |