how to invoke javascript in ASP.NET page??

M

Matthew Louden

I tried the following to invoke javascript in ASP.NET page, but it didnt
work. Any ideas??

Response.Write("<script language=""JavaScript"">alert('Hello')</script>")
 
J

Jim Cheshire [MSFT]

Matthew,

Using Response.Write will work, but you have no control over where the
script is written unless you use inline script delimiters. A better option
would be to use RegisterClientScriptBlock or RegisterStartupScript along
with a StringBuilder object to dynamically build your script. Bear in mind
that if you know what the script needs to be, you can just add it to HTML
view as you would with an HTML file. You would only need to use
server-side code for your script if you need to programmtically write your
script.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
 

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,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top