How to Change Application Page Title Dynamically In C# Code Behind



TODO:

Have you ever wanted to change the title of your Application Page dynamically?

 

SOLUTIONS:

protected void SetPageTitles(string Title)
{
     ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitle");
     contentPlaceHolder.Controls.Clear();
     LiteralControl title = new LiteralControl();
     title.Text = Title;
     contentPlaceHolder.Controls.Add(title);

     contentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitleInTitleArea");
     contentPlaceHolder.Controls.Clear();
     title = new LiteralControl();
     title.Text = Title;
     contentPlaceHolder.Controls.Add(title);
}

 

NOTES:

There are no notes on this topic.



Comments (2) -

Peabody
Peabody
2/4/2014 9:52:35 AM #

Works great!

I am fairly new to SP and I just can't wrap my head around why I have to declare 2 LiteralControls if they both have the same content.
But if I doesn't, it won't work...

Anyway, thank you very much. Smile

Donnie Wishard
Donnie Wishard
2/4/2014 10:47:14 AM #

glad it worked for you.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading