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