how to invoke javascript in ASP.NET page??

  • Thread starter Thread starter Matthew Louden
  • Start date Start date
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>")
 
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.

--------------------
 
Back
Top