Set Page Title Dynamically in Asp.Net From Page and Custom Control
Dated: 27 Jan, 2011 12:30:08 AM
To dynamically set the page title from an asp.net page, you can use its Header property. The header property is an object of HtmlHead class (System.Web.UI.HtmlControls.HtmlHead). This class contains the property Title which represents the page title. The title property is string type and you can get or set the page title using this property.
The example below demonstrates how you can set the page title dynamically in asp.net (using C# or VB.NET)
C#
this.Header.Title = "Custom Page Title from Page";
VB.NET
Me.Header.Title = "Custom Page Title from Page"
If you are working inside a server control or custom control and want to set the page title from there (which is not recommended as if multiple controls try to set the page title, then there can be a confusion to developer), first you will need to access the contorl's parent page. this can be done by using the Page property of the control, and from there you can access the Header.Title property as shown below
The example below demonstrates how you can set the page title dynamically in asp.net from within a control (server control or custom control) [using C# or VB.NET]
C#
this.Page.Header.Title = "Custom Page Title from Control";
VB.NET
Me.Page.Header.Title = "Custom Page Title from Control"
Note: When you see the tooltip for Title property (in intellisense or object browser), it reads "
Gets the page title". but actually the Title property can be used to get or set the page title.
Click
here
to view/post comments.
Like this article? Now share it with your friends