Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the page title dynamically

Status
Not open for further replies.

wallaceoc80

Programmer
Jul 7, 2004
182
GB
I want to set the title of my page dynamically in ASP.NET.

I do this by giving the title tag an ID and including runat="server" as follows:
Code:
<title id="PageTitle" runat="server"></title>

Then in my code behind file I do this:
Code:
string strTitle = cmdTitle.ExecuteScalar().ToString();
PageTitle.InnerText = strTitle;

This works fine except that every so often for no apparent reason when I build my solution it removes the runat="server" attribute from the title tag and I get an error.

Anybody know why this happens?

Thanks for your help,

Wallace
 
it's because the VS.NET environment does not recognise runat as a valid attribute for the tag title. this happens when switching from source page view to html designer view.

you can get rid of this behavior by setting your VS.NET IDE not to validate the html source.

also you could use a server side variable for your title and modify this variable from code behind so you won't have to change the defautl behavior of vs.net.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top