By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 940 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

Changing document.title

P: n/a
Is it possible to change the document's title property from code behind (c#) ?
I need to build a dynamic title at runtime.
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Carlo Marchesoni wrote:
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...
Nov 18 '05 #2

P: n/a
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.

"Nick Gilbert" wrote:
Carlo Marchesoni wrote:
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...

Nov 18 '05 #3

P: n/a
> 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...
Nov 18 '05 #4

P: n/a
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.
PS: I posted three times since the Newsgroup reported an error - I don't know why.
"Nick Gilbert" wrote:
Carlo Marchesoni wrote:
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...

Nov 18 '05 #5

P: n/a
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.
PS: I posted three times since the Newsgroup reported an error - I don't know why.
"Nick Gilbert" wrote:
Carlo Marchesoni wrote:
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...

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.