[英]Get Page Title In Master Page Code Behind
I want to get the page title in c# master page code behind. 我想在c#主页面代码中获取页面标题。
I tried using Page.Header.Title;
我尝试过使用Page.Header.Title;
property but it return null
. 属性但它返回null
。
Please help me to get the title. 请帮我拿到标题。
Thanks in advance. 提前致谢。
Shibin VM Shibin VM
In your page head include runat="server"
then you can easily get the Page title by 在您的页面头部包含runat="server"
然后您可以轻松获取页面标题
string Title = Page.Title;
EDIT: 编辑:
Using the Title property of Page requires a header control on the page. 使用Page的Title属性需要页面上的标题控件。 (eg <head runat="server" />
). (例如<head runat="server" />
)。
You can set the page title on Page_Load Event like this 您可以像这样在Page_Load事件上设置页面标题
protected void Page_Load(object sender, EventArgs e)
{ Page.Title = "Page Title"; }
and get the page title using 并使用获取页面标题
string title = Page.Title;
在您的母版页中试试这个
string Title = "Your Site: " + this.Page.Title;
设置内容页面的Title
属性<%@ Page Title="Contact us" ../>
并处理母版页的加载或初始化事件以获取Page.Title
或Page.Header.Title
。
Use this in your html tag, it has worked for me <%: Page.Title %>
. 在你的html标签中使用它,它对我<%: Page.Title %>
。
For eg: <li class="active"><%: Page.Title %></li>
. 例如: <li class="active"><%: Page.Title %></li>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.