Get the title of the page in the code of the main page

I want to get the page title in the code of the C # main page.

I tried using the Page.Header.Title; property Page.Header.Title; but it returns null .

Please help me get the title.

Thanks in advance.

Shibin V.M.

+6
source share
5 answers

In the page title runat="server" you can easily get the page title

 string Title = Page.Title; 

EDIT:

Using the Title property for a page requires managing the title on the page. (for example, <head runat="server" /> ).

+14
source

You can set the page title in a 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; 
+4
source

try this on the main page

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

Set the Title attribute of the content pages <%@ Page Title="Contact us" ../> and process the start page of Load or Init to get Page.Title or Page.Header.Title .

+2
source

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

0
source

Source: https://habr.com/ru/post/901786/


All Articles