SolutionCottage.com
Posted  21 Nov 2008 - 20:20:51

Category: ASP.net


Setting Page title in master page from controls.

Issue:
Sometimes you wish to set the title of the page based on what content you have placed on it. Say you have a blog and you want the title of this post to end up in the page title. You probably use masterpages.

Solution:
First off, set the main title in the Masterpage to something like this:

<title id="title" runat="server">www.solutioncottage.com</title>


Then, from any page, set the page title like this:

((HtmlGenericControl)Page.Master.FindControl("title")).InnerText = ((Label)sender).Text;


I realise this is a bit dirty since FindControl might not always find controls, based on different conditions. In this cause you're pretty safe, and it's more to give you an idea how to access the title. On anything more than an experiment, you should add checks if the control was actually found etc.








0 comments:








© SolutionCottage 2008-2011 9/24/2017 1:01:38 PM