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. Prevent Submit in ASP.Net Button

Prevent Submit in ASP.Net Button

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascriptasp-netquestion
2 Posts 2 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.
  • M Offline
    M Offline
    Matias Szulman
    wrote on last edited by
    #1

    Hi! I'm developing a site with many pages with the same problem. The user may click a button which will show a popup (javascript:window.showModalDialog). Now, depending on what the user does in that popup, I return different values in a javascript variable. The full javascript code is the following: function ShowProductList(paramName, paramValue) { var winArgs; var winSettings = 'center:yes;resizable:no;help:no;status:no;dialogWidth:570px;dialogHeight:286px'; winArgs = window.showModalDialog('ProductList.aspx?ParamName=' + paramName + '&ParamValue=' + paramValue, winArgs, winSettings); if(winArgs != null) { } } Now, this works great. But I have this problem. When the users clicks Cancel in the popup, I return null in winArgs. I need the page not to submit if winArgs is null, but no matter what I try, I can't stop it submitting. Any thoughts? Every piece of help will be much appreciated Thanks in advance, Matias

    C 1 Reply Last reply
    0
    • M Matias Szulman

      Hi! I'm developing a site with many pages with the same problem. The user may click a button which will show a popup (javascript:window.showModalDialog). Now, depending on what the user does in that popup, I return different values in a javascript variable. The full javascript code is the following: function ShowProductList(paramName, paramValue) { var winArgs; var winSettings = 'center:yes;resizable:no;help:no;status:no;dialogWidth:570px;dialogHeight:286px'; winArgs = window.showModalDialog('ProductList.aspx?ParamName=' + paramName + '&ParamValue=' + paramValue, winArgs, winSettings); if(winArgs != null) { } } Now, this works great. But I have this problem. When the users clicks Cancel in the popup, I return null in winArgs. I need the page not to submit if winArgs is null, but no matter what I try, I can't stop it submitting. Any thoughts? Every piece of help will be much appreciated Thanks in advance, Matias

      C Offline
      C Offline
      ChrisAdams
      wrote on last edited by
      #2

      You could try cancelling the event to stop it from passing onto the next event handler, which is causing the post back. In IE it would be something like window.event.cancelBubble = true; Alternatively, switch the auto postback off for the button, and then within your function call the postback function yourself.

      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