Monday, June 14, 2010

Change Page title dynamically in ASP.NET using C#.NET

In this simple article you will learn to change title of web page dynamically.

Create a web application in c#

Drag a button and one textbox on the form

Then write code on form load event


protected void Page_Load(object sender, EventArgs e)

{

this.Title = "Page Default Title";

Button1.Text = "Change Title of page";



}


After that write some code on button click even



protected void Button1_Click(object sender, EventArgs e)

{

this.Title = TextBox1.Text.Trim();

Label1.Text = "Page title is changed to " + TextBox1.Text.Trim();

}



This is simple code to change title of page it is useful for indexing of your page in search engines.

1 comment:

  1. Well that is pretty simple. But How would update your page title if you have a tag element inside a ListView Control, that will change according to the data you're retrieving. For example the tilte of a book. Then you want to display that title in your page title. That's what I like to accomplish.

    ReplyDelete