Dynamic Title

  • Thread starter Thread starter niju
  • Start date Start date
N

niju

Hi there,
I am dynamically populating title for my web page. Here is the code
<title id="titleLabel" runat="server"></title>

Code behind
-----------
titleLabel.InnerText = myArrayList[1].ToString();

However, after compiling the page few times runat="server" disappears
and my page doesn't compile. When this happens this is what code
looks like

<title id="titleLabel" ></title>

How can I resolve this problem?
Many thanks
Niju
 
I'm assuming your using Visual C#?

This problem is related to the dissapearing OnInit code that occurs with
Visual C#. I had the same problem ages ago. Basically, I was told by MS that
there was a DLL problem (not one of their DLLs they were quick to point out)
that was deleting code. It's to do with the designer view.

The fix they gave me was to stop using designer view, and to change some
options. Set things like "open web pages in html view" and things like that.

Most annoying, but they assured me they wouldn't be writing a fix, so I've
been without design view for 9months. Everything is fixed in VS2005 though,
apparently.

Good luck!


Dan
 
You can try the code below... you won't need to declare a server side
<title> element for this code to work. Just put the code to your Page_Load
event.

string titleScript = "<script>document.title = 'Insert your title
here';</script>";
RegisterClientScriptBlock("changeTitle", titleScript);

HTH,

Onin
 
Back
Top