Get Page Title In Master Page Code Behind
Asked Answered
G

5

6

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

Greenlaw answered 18/11, 2011 at 5:40 Comment(0)
C
14

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

Crayfish answered 18/11, 2011 at 5:50 Comment(0)
S
4

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;
Saunders answered 18/11, 2011 at 5:54 Comment(0)
G
2

try this in your master page

string Title = "Your Site: " + this.Page.Title;
Guano answered 18/11, 2011 at 5:45 Comment(0)
P
2

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.

Phosphaturia answered 18/11, 2011 at 5:48 Comment(0)
Z
0

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

Zephan answered 13/3, 2018 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.