Shibin V.M
Shibin V.M

Reputation: 431

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

Upvotes: 6

Views: 14255

Answers (5)

Libino
Libino

Reputation: 27

Use this in your html tag, it has worked for me <%: Page.Title %>.
For eg: <li class="active"><%: Page.Title %></li>.

Upvotes: 0

Karthik
Karthik

Reputation: 2399

try this in your master page

string Title = "Your Site: " + this.Page.Title;

Upvotes: 2

Prasanth
Prasanth

Reputation: 3031

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;

Upvotes: 4

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

Upvotes: 14

KV Prajapati
KV Prajapati

Reputation: 94645

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.

Upvotes: 2

Related Questions