IT Community - Software Programming, Web Development and Technical Support

How to Dynamically Setting the Page's Title in ASP.NET 2.0?

This is a discussion on How to Dynamically Setting the Page's Title in ASP.NET 2.0? within the C# Programming forums, part of the Software Development category; How to Dynamically Setting the Page's Title in ASP.NET 2.0?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-24-2007, 12:33 AM
Archer Archer is offline
D-Web Programmer
 
Join Date: Jun 2007
Posts: 52
Archer is on a distinguished road
Question How to Dynamically Setting the Page's Title in ASP.NET 2.0?

How to Dynamically Setting the Page's Title in ASP.NET 2.0?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 12:35 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to Dynamically Setting the Page's Title in ASP.NET 2.0?

One of the many new features found in ASP.NET 2.0 is the programmatically-accessible <head> region, which can be added to an ASP.NET page using the following markup:
<head runat="server">
<title>Untitled Page</title>

... other <head>-level elements ...
</head>
The above markup (less the"... other <head>-level elements ..." part) is what Visual Studio adds to a new ASP.NET page or master page, by default. Note the runat="server". When an ASP.NET page is requested, the ASP.NET engine parses the HTML portion and creates the page's control hierarchy. During this process, the markup that maps to server-side controls is converted into an appropriate object instance. For example, during this process the TextBox Web control's markup is parsed (<asp:TextBox runat="server" id="myTextBox" ... />) and a TextBox class instance is created to participate during the events of the page's lifecycle.
The runat="server" portion is what instructs the ASP.NET engine that a particular piece of markup is a server-side control versus static HTML. The <head runat="server"> markup is instantiated as an HtmlHead class instance, which has properties mapping to <head>-level settings, including:
• Title - the page's title
• Style - a collection of cascading style sheet (CSS) entries defined for the page
In order to be able to programmatically access these <head>-level settings, you need to be certain to add the <head runat="server"> to your ASP.NET page or master page, if it's not present already.
Programmatically Working with the <head> Region
Assuming you have a programmatically-accessible <head> region defined in your page or the page's master page, you can programmatically access it using the Page class's Header property. For example, to programmatically set the title of a page, add the following line of code to the page's Page_Load event handler:
Page.Header.Title = "The current time is: " & DateTime.Now.ToString()
Alternatively, you can use the Page.Title property as a shortcut to Page.Header.Title. Furthermore, if you are using master pages, this code can work, as written, from either the master page or the ASP.NET page that uses the master page. In such a scenario, the <head> region should be defined in the master page, but the ASP.NET page can still access it via Page.Header.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i disable the title bar in JInternalFrame saravanan Java Programming 7 03-28-2008 06:33 AM
How do I change another window's title, that is, the content of title bar at the top itbarota HTML, CSS and Javascript Coding Techniques 1 09-13-2007 03:02 AM
How to give bug title & bug description fo ODD division? devarajan.v Quality Engineering and Methodologies 1 07-27-2007 12:14 AM
Title Tag Optimization Tips vadivelanvaidyanathan Search Engine Optimization 0 03-30-2007 02:58 AM
SEO Optimization - Page Title drecko Search Engine Optimization 2 02-19-2007 01:28 AM


All times are GMT -7. The time now is 09:28 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0