Best way to modify HTML HEAD from web control

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

I have a webcontrol for the navigation our site. I'd like to load some
javascript with it. Normally, one would put these in the HEAD of the parent
page. Is there a preferred method for adding tags to the HEAD of a parent
page from a web control?

In the past, I've simply created a 'header tags' control and any time
another controls needs to write something in the head, I add that to this
other control. That doesn't seem to be the best method.

-Darrel
 
Hi mate,

use the Page.RegisterClientSideScript(string ID, string Script) method
and this will take care of it all for you. This way you can specify
your stuff in a different file or wherever and just pass in the string
and off you go.

Cheers
AndrewF
 
use the Page.RegisterClientSideScript(string ID, string Script) method
and this will take care of it all for you. This way you can specify
your stuff in a different file or wherever and just pass in the string
and off you go.

Instead of passing the entire script, can one just pass a link to the .js?

In otherwords, I don't need to actually put JS in the HEAD, but just the
SCRIPT tag:

<script type="text/javascript" src="/myscript.js"></script>

-Darrel
 
note: RegisterClientSideScript add the script right after the <form>, not
inside the <head>

-- bruce (sqlwork.com)
 
Back
Top