With ASP.Net 2.0 you can use the Title
property to change the page title :
Page.Title = "New Title";
But since in ASP.Net 1.1 there isn't a Title
property in the Page
class, how can I change the page's title from the code-behind ?
With ASP.Net 2.0 you can use the Title
property to change the page title :
Page.Title = "New Title";
But since in ASP.Net 1.1 there isn't a Title
property in the Page
class, how can I change the page's title from the code-behind ?
With ASP.Net 1.1, first you have to set the runat
attribute on the title markup :
<title id="PageTitle" runat="server">WebForm1</title>
Then from the code behind :
C#
// We need this name space to use HtmlGenericControl
using System.Web.UI.HtmlControls;
namespace TestWebApp
{
public class WebForm1 : System.Web.UI.Page
{
// Variable declaration and instantiation
protected HtmlGenericControl PageTitle = new HtmlGenericControl();
private void Page_Load(object sender, System.EventArgs e)
{
// Set new page title
PageTitle.InnerText = "New Page Title";
}
}
}
VB
Imports System.Web.UI.HtmlControls
Namespace TestWebApp
Public Class WebForm1
Inherits System.Web.UI.Page
Protected PageTitle As HtmlGenericControl = New HtmlGenericControl()
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
PageTitle.InnerText = "New Page Title"
End Sub
...
End Class
End Namespace