Register Client Script

G

Goh

Hi,

May I know how to register a java script inside the <head> tag not the
body? I found only got method that able register at the body like
RegisterStartupScript and RegisterClientScriptBlock.
I would like to register this script inside user control. and this
script must be run when the page is load.
Got any method that able to call to solve this problem?


Thanks in advance/
 
R

Rick Strahl [MVP]

There isn't a way to do this directly. Why do you want to do this? ASP.NET
puts the code inside of the Form tag so that's in the scope of the page
logic and so that it can run Onload code easily.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog
 
K

Kevin Spencer

You should be able to do this by creating a "runat=server" head tag in your
page, and supplying an HtmlGenericControl in the CodeBehind to work with it
programmatically. The InnerHtml property can then be used to add a block of
JavaScript to the contents of the Control. Alternatively, you could add a
LiteralControl containing the JavaScript to the Controls Collection of the
Control.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.
 
E

Edwin Knoppert

Yes, i wonder'd myself about MS code being placed inside the BODY tags.

Your explaination makes it clear, in fact it's i find this logical because
it's modular this way.
If you ever add another form to the html code, there could be specific JS
code for that form only.
(I am not saying these are nested functions, unique names might still be
required. :) )
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top