I'm not sure this is the correct way to do this, but this is what I figured out.
I added an OnInit() function to my WebControl: protected override void OnInit( System.EventArgs e ) { if( title.Length > 0 ) { Page p = this.Page; bool found = false; foreach( Control control in p.Controls ) { if( found ) break; if( control as LiteralControl != null ) { int pos = ((LiteralControl)control).Text.ToUpper().IndexOf( "<HEAD>" ); if( pos > 0 ) { found = true; ((LiteralControl)control).Text = ((LiteralControl)control).Text.Insert( pos+6, "\r\n<title>"+title+"</title>" ); } } } } } Not the cleanest way to do it, but it works. The properties seem to all be set before the call to OnInit() so you can use the attributes in the ASP/HTML tag. If anyone know of a better way, please let me know. Mike Collins > -----Original Message----- > From: Collins, Michael G [mailto:[EMAIL PROTECTED]] > Sent: Thursday, May 23, 2002 1:01 PM > To: [EMAIL PROTECTED] > Subject: [DOTNET] How to insert into the Head, Title, Style, > Script tags > > > OK. I know that this has been discussed, but I have not been > able to find a good explanation of this yet. The archives are > not easy to search. > > I want to be able to update the content of the <head></head> > tag or the <title></title> tag or the <script></script> tag > from down within my page. > > I have a custom control that can dig down into the DOM on the > server side, but I can't seem to get it to make any changes > that seem to take affect and I can't get any of it to work > without setting the runat="server" attribute for the tags I > want to change. > > The next problem is that the editor (VS.NET) likes to remove > the runat="server" attribute for any tag that DS feels should > not have the attribute. > > > So my questions are: > > Question 1: > Is there a way to access a general HTML tag on the server? I > need to be able to change the InnerHtml for the tag and have > it show up on the browser. Right now I am trying to use the > Render(HtmlTextWriter output) function: > > Page p = this.Page; > bool found = false; > foreach( Control control in p.Controls ) > { > if( found ) > break; > > if( control as HtmlGenericControl != null ) > { > if( > ((HtmlGenericControl)control).TagName.ToUpper() =="HEAD" > ) > { > found = true; > string newStr = > "\r\n<title>"+title+"</title>" + > ((HtmlGenericControl)control).InnerHtml; > > ((HtmlGenericControl)control).InnerHtml += newStr; > } > } > } > > The InnerHtml has the data I want, but when I change it > nothing passes through to the browser. Do I need to do this > before the Render() function or somewhere else? > > Also this will ONLY work if I set runat="server" for the <head> tag. > > So Question 2: > Is there a way to change what VS.NET deems correct HTML? Is > there a template somewhere that I can change to allow > runat="server" to be OK for the tags I want? > > > BTW: Microsoft might want to conceder making the entire DOM > available on the server side in a similar fashion to the way > IE6 sees the DOM on the client side. That way we can adjust > the DOM before it gets sent to the browser. (Maybe there is a > way to do this, but I can't find it.) > > Thanks in advance, > Mike Collins You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.