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
In FindControl () method is also best way to fetch the masterpage control to content page. FinControl () is by default inside method of masterpage. Label control named lblUserName on master page. Label lblUserVal = (Label)Page.Master.FindControl ("lblUserName"); On explorer add New Item MASTER PAGE named “MainMaster.master"
Programmatically setting the page's Title property using code like Page.Title="title" or Page.Header.Title="title". Content pages don't have a <title> element, as it's defined in the master page. Therefore, to set a content page's title you can either use the <%@ Page %> directive's Title attribute or set it programmatically.
Using the Title property of Page requires a header control on the page. (e.g. head runat="server" / ). You should remove the Title="" from the aspx page. It will override the Title set in your code-behind protected void Page_Load (object sender, EventArgs e) { if (!Page.IsPostBack) { this.Title = "Title"; } }
An ASP.NET page can specify its title in one of the following ways: 1 By placing the value directly within the <title> element 2 Using the Title attribute in the <%@ Page %> directive 3 Programmatically setting the page's Title property using code like Page.Title="title" or Page.Header.Title="title". More ...
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" />
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With