问题
I want to get the page title in c# master page code behind.
I tried using Page.Header.Title; property but it return null.
Please help me to get the title.
Thanks in advance.
Shibin V.M
回答1:
In your page head include runat="server" then you can easily get the Page title by
string Title = Page.Title;
EDIT:
Using the Title property of Page requires a header control on the page. (e.g. <head runat="server" />).
回答2:
You can set the page title on Page_Load Event like this
protected void Page_Load(object sender, EventArgs e)
{ Page.Title = "Page Title"; }
and get the page title using
string title = Page.Title;
回答3:
Set Title attribute of content pages <%@ Page Title="Contact us" ../> and handle the Master page's Load or Init event to get Page.Title or Page.Header.Title.
回答4:
try this in your master page
string Title = "Your Site: " + this.Page.Title;
回答5:
Use this in your html tag, it has worked for me <%: Page.Title %>.
For eg: <li class="active"><%: Page.Title %></li>.
来源:https://stackoverflow.com/questions/8178243/get-page-title-in-master-page-code-behind