Set the Title of a Webform programatically


The Title of a WebForm in ASP.Net is determined by the Title Attribute in the HTML View. On a closer look, you will find that there is no property in the default or any other namespace that helps you to change that programmatically.
This simple workaround accomplishes the same with ease.

You need to modify the current <Title> tag to be accessible in the code.

So add the <runat='server'> tag to it. And assign an ID to the same.

After this it might look like below,

<title id="pgTitle"> Default Title </title>

Next step is to add it to code, as follows.

protected System.Web.UI.HtmlControls.HtmlGenericControl pgTitle;

And last but not the least, change the title in the code, using its InnerText property

pgTitle.InnerText = "User Page"
 
Ebook Download
View all
Learn
View all