append child

  • Thread starter Thread starter josh
  • Start date Start date
J

josh

Hi,

I wish to know if there is a way to have for ex.

<head>
<title>xxx</title>
</head>

a way to take the <title> (getElementsByTagName()...) and
then to use a sintax like appendChild to append some <script> to
<head>

I view that if I use head.innerHTML then all the content into <head>
is overwritten!

Thanks

P.S.
FindControl give me the way only to take web controls that have an ID
but how to take controls or
HTML tag that does not have that ID?

Thanks
 
Provided the page is an ASP.NET page, you can get the title without the
kludge, as it is exposed.

string title = Page.Header.Title;

You can then do what you want with it. Unless your JavaScript absolutely has
to be in the <head> region, you should consider one of the registration
commands for JavaScript (RegisterStartUpScript or RegisterClientSideScript),
as they will automatically place the script at the top or where it is used.
This is found in the ClientScriptManager class.

If you absolutely must add to the head section, you can do something like
this:

Page.Header.Controls.Add(ctl);

As an example:

HtmlGenericControl ctl = new HtmlGenericControl("script");
ctl.Attributes.Add("type", "text/javascript");
ctl.InnerHtml = "alert('Page name = " + Page.Header.Title + "');";
Page.Header.Controls.Add(ctl);

You can also use a literal control in the same manner, but you will have to
write out the tags as well.


--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
Back
Top