how to invoke javascript in ASP.NET page??

Discussion in 'ASP .Net' started by Matthew Louden, Nov 18, 2003.

  1. 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 Louden, Nov 18, 2003
    1. Advertisements

  2. 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

    Jim Cheshire, MCSE, MCSD [MSFT]
    Developer Support

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

    Jim Cheshire [MSFT], Nov 18, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.