realize
Share Share This

Popular Tags

View All Posts

Blog Roll

Wednesday September 9, 2009

Set Page Title in .NET Theme

.Net themes can be a wonderful thing. We use it often to apply a different look and feel based on the Domain where the page is hosted or some affiliation the user has with the site. However .NET doesn’t supply a straight forward means of changing the Title of your web pages based on the Theme being applied. I’ve found a nice easy little work around for anyone out there looking for a way to do this. Here is all you have to do:

  1. Add an asp label to your page with visibility set to false and a skinID. Don’t forget the runat=“server” (e.g. <asp:Label ID=“lblPageTitle” runat=“server” SkinID=“PageTitleSkin” Visible=“false” /> )
  2. Add a skin to your skins file that set’s the text of this label to what you want the page title to be (e.g. <asp:Label SkinID=“PageTitleSkin” runat=“server” Text=” Page Title Goes Here ” /> )
  3. In the page_load of your code behind page add this line of code: Page.Title = lblPageTitle.Text;

Because skinning occurs on pre_init the label has already been skinned by the time the page_load runs. by setting the visible property of the label to false the label doesn’t disrupt your page. But it’s text is usable by the code behind to create the title.

I hope this helps anyone out there looking for a work around for this. I didn’t find any mention of skinning the page title when I looked so I had to come up with this one on my own.

Happy Coding :-}

Gregg Duncan

 
 

Leave a Comment

«   »