xp_dirtree and Dynamic Page Title

The xp_dirtree extended procedure in SQL Server (7.0 and 2000) will list the subdirectories in the specified directory. Usage: EXEC master.dbo.xp_dirtree 'C:\Windows'

As I learnt today, the title (browser window title) of an ASP.NET page can be changed programatically. Here how ...

In the HEAD section of the ASP.NET page (.aspx) define the title as a server side control:

<TITLE ID=PageTitle RUNAT=server></TITLE>

... and in the code-behind (.aspx.vb) or inline code, define ...

Protected PageTitle As New HtmlGenericControl

... and set the title from anywhere in the code as ...

Me.PageTitle.InnerText = "Hello World"

A cool technique to implement for a template-driven UI.

3 Comments

  • Dynamically changing the title this way is a great tip, thanks! I think I'll do this for CSS links as well.

  • Thanks for the tip! It is just what I was looking for.

  • Definitely there a better alternative so that VS.NET does not play tricks with you, use the placeholder tag.

    &lt;HTML&gt;

    &lt;HEAD&gt;

    &lt;asp:PlaceHolder id=&quot;titlePlaceHolder&quot; runat=&quot;server&quot; /&gt;

    &lt;/HEAD&gt; &lt;BODY&gt;

    ...

    ...

    ...

    &lt;/BODY&gt;&lt;/HTML&gt;



    In the codebehind...



    protected System.Web.UI.WebControls.PlaceHolder titlePlaceHolder;

    protected System.Web.UI.HtmlControls.HtmlGenericControl PageTitle;



    private void Page_Load(object sender, System.EventArgs e)

    {

    PageTitle= new System.Web.UI.HtmlControls.HtmlGenericControl(&quot;title&quot;);

    titlePlaceHolder.Controls.Add(PageTitle);

    PageTitle.InnerHtml=&quot;Whatever title you want!&quot;;



    }

Comments have been disabled for this content.