Tutorial :Changing Title in Overridden OnPreRender


in my overridden OnPreRender function, I can modify the text of a label: Label1.Text='in OnPreRender'
However, I cannot do this.Header.Title='changed in OnPreRender'
The only way to change the browser title is by doing:

this.Controls.Remove(this.Controls[0]);    this.Controls.AddAt(0, new LiteralControl("<html><head><title>changed in OnPreRender</title></head></html>")  

Why can't I change the Title just like the Label? Nothing has rendered yet...


so now, without even adding runat="server" to the title tag, as Partario suggested, I am able to call this.Header.Title both in Page_PreRender and OnPreRender.

It wasn't working because I had the other code ('this.Controls...') uncommented, which apparently takes precedence.

So the result is, if you literally remove the first LiteralControl and add a new one as I originally did, you cannot then call this.Header.Title.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »