Get Page Title In Master Page Code Behind

可紊 提交于 2019-12-23 09:32:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!