Set Page Title in code behind

N

Nevyn Twyll

In my code behind page, I want to dynamically set the page title of my page
(the one that shows on IE's toolbar). How do I do that?


- Nevyn
 
D

Daniel Fisher\(lennybacon\)

ASP.NET 1.1

in webform:
....
<title ID="HtmlTitle" runat="server></title>
....

in codebehind:
....
protected GenericHtmlControl HtmlTitle;
....
void Page_Load(...){
this.HtmlTitle.Value = "blabla";
....

--Daniel Fisher(lennybacon)
 
N

Nevyn Twyll

I can't find GenericHtmlControl in the ASP.NET 1.1 docs or autocomplete.

Help?
 
N

Nevyn Twyll

Ah. Did you mean HtmlGenericControl?

Here's what I did that worked

System.Web.UI.HtmlControls.HtmlGenericControl HtmlTitle;

HtmlTitle = (HtmlGenericControl) FindControl("htmltitle");

HtmlTitle.InnerText = "What I want it to say";
 
P

Peter Rilling

Just a word of caution with this though. Sometimes when you switch between
the designer and the HTML view, the <title> tag is reset such that the
@runat attribute is removed.
 
L

Lars-Erik Aabech

To get around the IDE rewriting of the <title runat="server".. stuff, I
usually put a literal control inside the title tag.
Like:
<title><asp:Literal runat="Server" id="litTitle"/></title>

If you insert this in HTML view, and swap to design view, you get the member
field automagically, and can set it's Text property in ie. Page_Load.. :)

Lars-Erik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top