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
    1. Advertising

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

    Jim Cheshire, MCSE, MCSD [MSFT]
    Developer Support
    ASP.NET


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

    --------------------
    >From: "Matthew Louden" <>
    >Subject: how to invoke javascript in ASP.NET page??
    >Date: Tue, 18 Nov 2003 08:53:48 -0800
    >Lines: 6
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    >Message-ID: <>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >NNTP-Posting-Host: 209.117.12.90
    >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:191749
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >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>")
    >
    >
    >
    Jim Cheshire [MSFT], Nov 18, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg H
    Replies:
    1
    Views:
    426
    David Waz...
    Jul 3, 2003
  2. Samuel
    Replies:
    0
    Views:
    557
    Samuel
    Jul 30, 2003
  3. Aimee
    Replies:
    3
    Views:
    494
    John Timney \(Microsoft MVP\)
    Oct 21, 2004
  4. Standist
    Replies:
    0
    Views:
    1,374
    Standist
    Feb 8, 2006
  5. Replies:
    1
    Views:
    134
    Van den Driessche Willy
    Sep 20, 2006
Loading...

Share This Page