Changing document.title

G

Guest

Is it possible to change the document's title property from code behind (c#) ?
I need to build a dynamic title at runtime.
 
N

Nick Gilbert

Carlo said:
Is it possible to change the document's title property from code behind (c#) ?
I need to build a dynamic title at runtime.
Yes you can run any tag at the server end to turn it into an Html
Generic control:

<title id="theTitle" runat="server">

Then in your code behind you declare the title has an HtmlGenericControl
(?) and you can then do:

theTitle.Text= "my title";

I notice you posted that question 3 times... Be patient when posting to
news groups. It can take half an hour or more for your message to appear
in your mail client.

Nick...
 
G

Guest

I declared runat=server and inserted this declaration:
protected System.Web.UI.HtmlControls.HtmlGenericControl AV0010Title;

in my code behind, but there is no "Text" attribute for this at all. Which property do I have to set in order to see the Title Text.

PS: I posted three times since the Newsgroup reported an error - I don't know why.
 
N

Nick Gilbert

I declared runat=server and inserted this declaration:
protected System.Web.UI.HtmlControls.HtmlGenericControl AV0010Title;

in my code behind, but there is no "Text" attribute for this at all. Which property do I have to set in order to see the Title Text.

Sorry - you need to use the "InnerText" property:

protected System.Web.UI.HtmlControls.HtmlGenericControl theTitle;
private void Page_Load(object sender, System.EventArgs e) {
theTitle.InnerText="foo";
}

Nick...
 
E

Edward

hi, Carlo,

my way is use Literal Control, you can put the following line inside the
<head></head>:
<title><asp:Literal id="ltTitle" runat="server"/></title>

then you can set it in your Page_load or other handler, using Text
attribute.

anyway, you should declare one relevant object in your codebehind file.

Hope it' useful to you.
I declared runat=server and inserted this declaration:
protected System.Web.UI.HtmlControls.HtmlGenericControl AV0010Title;

in my code behind, but there is no "Text" attribute for this at all. Which
property do I have to set in order to see the Title Text.
 
E

Edward

BTW, if you use <title> , you should use InnerHtml instead of Text.

That is, AV0010Title.InnerHtml = "what you dynamically assign";
I declared runat=server and inserted this declaration:
protected System.Web.UI.HtmlControls.HtmlGenericControl AV0010Title;

in my code behind, but there is no "Text" attribute for this at all. Which
property do I have to set in order to see the Title Text.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top