How to set Page#39;s Title from a web content page in ASP.NET 3.5(如何从 ASP.NET 3.5 中的网页内容页面设置页面标题)
问题描述
我已经阅读了很多关于如何做到这一点的帖子/文章,但我仍然没有从内容页面获得页面标题集.我的页面呈现正常,但我无法从内容页面获取标题集(所有页面的标题都按照母版页设置).这是我的母版页的代码隐藏:
部分类zSEO继承 System.Web.UI.MasterPageProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)Page.Header.Title = "5Zyo5q+N54mI6aG15Lit5Yqo5oCB6K6+572u"结束子结束班
这是母版页的其余部分:
<%@ Master Language="VB"启用主题=真"继承=zSEO"CodeFile="zSEO.master.vb" %><!DOCTYPE htmlPUBLIC "-//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>头部><身体><form id="form1" runat="server"><div id="容器"><div id="内容"><asp:contentplaceholder id="ContentPlaceHolder1" runat="server"></asp:contentplaceholder>
</表单>
然而,我想在网页内容页面中建立页面的值,并将其放置在我的测试内容页面中:
公共部分类 zShowAd继承 System.Web.UI.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)Page.Header.Title = "5Zyo5YaF5a65KOWtkCnpobXpnaLkuK3liqjmgIHorr7nva4gVElUTEUg5YC8"结束子结束班
奇怪的是,我无法让调试器停在内容页面的上面一行——只能停在母版页的相应行上.显然,我对此感到困惑.
我已经读过有其他方法可以做到这一点,但从我在 Scott Mitchell 的教程中阅读的内容来看,这似乎是可能的:在 ASP.NET 中动态设置页面标题.具体来说,我试图从文章中遵循这一点:此外,如果您使用母版页,则此代码可以按照编写的方式从母版页或使用母版页的 ASP.NET 页工作.在这种情况下,应在母版页,但 ASP.NET 页仍然可以通过 Page.Header 访问它.
那么需要做的就是这个
MasterPage.Master
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) 处理 Me.InitMe.Page.Title = "5Zyo5q+N54mI6aG15Lit5Yqo5oCB6K6+572u"结束子
Default.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 处理 Me.LoadMe.Page.Title = "5ZyoIEFTUFgg6aG16Z2i5Lit5Yqo5oCB6K6+572u"结束子
通过这种方式,您的母版页标题设置在您的内容页标题之前.如果您未从内容页面设置标题,则母版页将是默认标题.如果您确实从内容页面设置了标题,那么它将覆盖它.
I've read through quite a bit of posts/articles on how to do this and I still am not getting the page title set from the content page. My pages render OK except I can't get the title set from the content page (all the page's have Title set as per the master page). Here's the codebehind for my master page:
Partial Class zSEO
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Header.Title = "RHluYW1pY2FsbHkgc2V0IGluIE1hc3RlciBwYWdl"
End Sub
End Class
Here is the rest of the master page:
<%@ 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>
Yet, it is in the web content page that I want to establish the value of the for the page and I have placed this in my testing content page:
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 = "RHluYW1pY2FsbHkgc2V0IFRJVExFIHZhbHVlIGluIHRoZSBjb250ZW50KGNoaWxkKSBwYWdl"
End Sub
End Class
Strangely, I cannot get the debugger to stop on the line above in the content page - only on the corresponding line in the master page. Clearly, I am confused on this.
I've read there are other ways to do this but this seemed to be possible from what I read at Scott Mitchell's tutorial at: Dynamically setting the Page Title in ASP.NET. Specifically, I tried to follow this from the article: "Furthermore, if you are using master pages, this code can work, as written, from either the master page or the ASP.NET page that uses the master page. In such a scenario, the region should be defined in the master page, but the ASP.NET page can still access it via Page.Header. "
So what needs to happen is this
MasterPage.Master
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Me.Page.Title = "RHluYW1pY2FsbHkgc2V0IGluIE1hc3RlciBwYWdl"
End Sub
Default.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Page.Title = "RHluYW1pY2FsbHkgc2V0IGluIEFTUFggcGFnZQ=="
End Sub
This way your master page title is set BEFORE your content page title. If you do not set a title from the content page, the masterpage will be the default title. If you do set a title from the content page, then it will override it.
这篇关于如何从 ASP.NET 3.5 中的网页内容页面设置页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 ASP.NET 3.5 中的网页内容页面设置页面标题


- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 使用 rss + c# 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01