如何从ASP.NET 3.5中的Web内容页面设置页面标题 [英] How to set Page's Title from a web content page in ASP.NET 3.5

查看:100
本文介绍了如何从ASP.NET 3.5中的Web内容页面设置页面标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关如何执行此操作的文章/文章,但仍然没有从内容页面获得页面标题集.除了无法从内容页面获取标题集(所有页面的标题均按照母版页设置)之外,我的页面呈现为OK.以下是我的母版页的代码:

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 = "Dynamically set in Master page"
    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>

但是,我要在Web内容页面中确定页面的值,并将其放在我的测试内容页面中:

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 = "Dynamically set TITLE value in the content(child) page"
End Sub

End Class

奇怪的是,我无法使调试器停止在内容页面的上一行-仅在母版页的相应行上停止.显然,我对此感到困惑.

我已经阅读了其他方法来执行此操作,但是从我在Scott Mitchell的教程中阅读的内容来看,这似乎是可能的:

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. "

推荐答案

所以这需要发生

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

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

通过这种方式,您可以在内容页面标题之前设置母版页面标题.如果未从内容页面设置标题,则母版页将为默认标题.如果您确实从内容页面设置了标题,那么它将覆盖它.

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中的Web内容页面设置页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆