ASP.NET:在母版页中具有通用的页面标题,并且每个页面都添加特定于页面的标题吗? [英] ASP.NET: Having common Page title in master page with each page adding page-specific title?
本文介绍了ASP.NET:在母版页中具有通用的页面标题,并且每个页面都添加特定于页面的标题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的主页如下:
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="PageTitlePlaceHolder" runat="server" />
</title>
内容页面如下:
<asp:Content ID="TitleContent1"
ContentPlaceHolderID="PageTitlePlaceHolder" runat="Server">
My Page
</asp:Content>
这可以通过在页面上放置内容页面特定的标题(在此示例中为我的页面")来实现.现在,我想在主页的标题中为站点名称添加一个全局前缀.所以我想要:
This works by placing the content page specific title on the page ("My Page" in this example). Now I want to add a global prefix to the title in my master page for the site name. So I want:
<head runat="server">
<title>
Example.com:
<asp:ContentPlaceHolder ID="PageTitlePlaceHolder" runat="server" />
</title>
但是,当我执行此操作时,内容页面仍在磁贴中没有"Example.com"的情况下呈现,就像被忽略了.
However, when I do this content pages are still rendered without "Example.com" in the tile, it's like it's ignored.
为什么会这样,我该如何实现?
Why is this happening and how can I achieve this?
推荐答案
在MasterPage后面的代码中尝试以下操作:
Try this in the code behind of the MasterPage:
void MasterPage_PreRender(object sender, EventArgs e)
{
Page.Title = "Example.com - " + Page.Title;
}
这篇关于ASP.NET:在母版页中具有通用的页面标题,并且每个页面都添加特定于页面的标题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文