Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Call Javascript Function

Call Javascript Function

Scheduled Pinned Locked Moved ASP.NET
javascripttutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lash20
    wrote on last edited by
    #1

    How do you call a javascript function when a button is clicked? I know you can use the OnClick event, but that will fire up everytime the button is clicked. I need to call the function only when certain criteria are met. For example private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { //Call Javascript function } } Thanks.

    C G R 3 Replies Last reply
    0
    • L Lash20

      How do you call a javascript function when a button is clicked? I know you can use the OnClick event, but that will fire up everytime the button is clicked. I need to call the function only when certain criteria are met. For example private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { //Call Javascript function } } Thanks.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can't call a javascript function from the server, all you can do is rerender the page and insert script that calls it. Is flag calculated based on client side state ? If so, use a custom validator. If it isn't, then just insert client side variables that have these values, so you can validate them on the client, and still avoid a postback.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • L Lash20

        How do you call a javascript function when a button is clicked? I know you can use the OnClick event, but that will fire up everytime the button is clicked. I need to call the function only when certain criteria are met. For example private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { //Call Javascript function } } Thanks.

        G Offline
        G Offline
        GaryWoodfine
        wrote on last edited by
        #3

        adding onto what chris wa saying you can check out my article here which helps explain things a bit more http://www.codeproject.com/useritems/JavascriptValidation.asp

        Kind Regards, Gary


        My Website || My Blog || My Articles

        1 Reply Last reply
        0
        • L Lash20

          How do you call a javascript function when a button is clicked? I know you can use the OnClick event, but that will fire up everytime the button is clicked. I need to call the function only when certain criteria are met. For example private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { //Call Javascript function } } Thanks.

          R Offline
          R Offline
          RaviJJain
          wrote on last edited by
          #4

          You can call javascript by just printing the script on page as below private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { reposne.write("javascript:alert('hi');") } }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups