BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

How To Dynamically Change Page Title?

To change page title with server side ASP.NET code you can use Title property of Page object. Your code could look like this:

[ C# ]

Page.Title = "New page title";

[ VB.NET

Page.Title = "New Page Title"

 

Note that Title property doesn't exist in ASP.NET 1.1. If you work in ASP.NET 1.1 environment you can change page title if you add runat="server" attribute to <title > tag. Use code like this:

[ HTML ]

<title id="PageTitle" runat="server">WebForm1</title>

[ 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";
            }

 

Or, to do it with VB.NET:

[ VB.NET ]

' We need this name space to use HtmlGenericControl
Imports System.Web.UI.HtmlControls
 
Namespace TestWebApp
 
    Public Class WebForm1
        Inherits System.Web.UI.Page
 
        ' Variable declaration and instantiation
        Protected PageTitle As HtmlGenericControl = New HtmlGenericControl()
 
        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
 
            ' Set new page title
            PageTitle.InnerText = "New Page Title"
        End Sub
 
...
 
    End Class
End Namespace



Related articles:

1. Using Excel Sheets as a Database Backend

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.