Hi,
ThunderMusic wrote:
> Hi,
> I'm making a Custom Web Control and I'm wondering how I can insert
> Javascript code into the head part of the document from within my web
> control... I lloked at the methods of the HtmlTextWriter output object from
> the Render method, but I didn't fiind anything. I have 2 questions :
>
> 1. Is it this important to put the javascript code into the head or it can
> be in the body without causing trouble?
It is not vital that JavaScript be placed in the HEAD part of the HTML
page. It is recommended, because the JavaScript parser will ready all
the functions placed there before starting to render the body, but it is
not a must.
Just make sure that your JavaScript code is placed before the call to
it, the best being placing the code in functions, and calling the
functions from an "onload" event of the body tag. Since the "onload"
event is fired only after the whole code (HTML and JavaScript) is parsed
and prepared, you're sure that your JavaScript environment is ready.
> 2. If it is important to put it in <Head>, how can I do it from my Web
> Control?
You can't with the default Page class. When I really have (or want to)
place code in the HEAD part, I use a self-written Custom control which I
use to register headers (CSS files, JavaScript files or code). Not the
most elegant way, but it works.
>
> Thanks a lot.
>
> ThunderMusic
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering:
http://www.galasoft-LB.ch
Private/Malaysia:
http://mypage.bluewin.ch/lbugnion
Support children in Calcutta:
http://www.calcutta-espoir.ch