Hello Everyone!
Exciting news for me today, my blog has officially moved to http://julieturner.net. Please head on over and check it out! The Page will be automatically redirected in 5 seconds.
Thanks!
Julie Turner
I'm currently dealing with a requirement where I need to the set an application page's title from the code behind.
By default the form has a ContentPlaceHolder control with a ContentPlaceHolderID="PlaceHolderPageTitle" which in the master page is the text that will fall in the header's title tag. Unfortunately, <asp:Content> controls are not added to the higherarchy at runtime so I can't access it directly.
There are good ways to modify this title on the client side with Javascript but client side code doesn't really suit my needs as the title will come from some custom manipulation that's better done on the server. It did cross my mind that I could do this minipulation and then post it back in script to have it update but it seemed kindof like taking the long way around. Anyway, long story short I found a way to access that title in the Page_Load event but if anyone out there has any better ideas I'd love to hear them.
using System.Web.UI.HtmlControls;
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){
HtmlTitle tagTitle = new HtmlTitle();
//Obviously this would be more complex code in practice
tagTitle.Text = "My new title here";
//The parent of "PlaceHolderPageTitle" is the HtmlTitle control
Page.Header.Controls.Remove(
Page.Header.FindControl("PlaceHolderPageTitle").Parent);
Page.Header.Controls.Add(tagTitle);
}
}