Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Page Title In Master Page Code Behind

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

like image 972
Shibin V.M Avatar asked Nov 18 '11 05:11

Shibin V.M


People also ask

How to get the masterpage control from the content page?

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"

How to set the page's title programmatically?

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.

How to use the title property of a page?

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"; } }

How do I set the page title in ASP NET?

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 ...


1 Answers

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" />).

like image 96
Sai Kalyan Kumar Akshinthala Avatar answered Nov 15 '22 06:11

Sai Kalyan Kumar Akshinthala