Reputation: 25
Similar to the question below, I am trying to grab the Title entered in the title tag in each page and use that to update an asp label to dynamically set the title on each page. I am trying only use the c# code on the master page, yet only empty strings are being returned by page.title when each page has a title such as:
<title>Graphs</title>
Get Page Title In Master Page Code Behind
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
string TempTitle = Page.Title;
title.Text = TempTitle;
}
}
Ok it seems 'Page.Title;' doesn't grab the text between the title tags, does anything?
Upvotes: 0
Views: 381
Reputation: 25
Problem was the asp title was empty as shown below
<%@ Page Title=""
Upvotes: 0
Reputation: 627
It doesn't make any sense to code in master page if you want to get title of each page in c#. Just use this code on each page.
string S = this.Page.Title;
YourLabel.Text = S;
Upvotes: 0