javascript within Custom Web Control

T

ThunderMusic

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?
2. If it is important to put it in <Head>, how can I do it from my Web
Control?

Thanks a lot.

ThunderMusic
 
L

Laurent Bugnion

Hi,
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top