I have an ASP.NET page which has a button it it. The button click launches a modal dialog box using javacript. Based on the value returned by the modal dialog box, i want to proceed with, or cancel the post back that happens. How do i do this?
+11
A:
Adding "return false;" to the onclick attribute of the button will prevent the automatic postback.
Wayne
2008-09-29 18:15:55
If any exceptions are thrown before the return false, the automatic postback will still occur.
Chris MacDonald
2008-09-29 18:33:34
A:
Basically what Wayne said, but you just need to put 'return false;' in the function that presents the modal. If it's the value you want, let the postback happen. If not, have the function return false and it will stop the submit.
Tom
2008-09-29 18:18:06
A:
function HandleClick()
{
// do some work;
if (some condition) return true; //proceed
else return false; //cancel;
}
set the OnClientClick attribute to "return HandleClick()"
chris
2008-09-29 18:18:30
+1
A:
Is this what you are trying to do?
<input type="button" id="myButton" value="Click!" />
<script type="text/javascript">
document.getElementById('myButton').onclick = function() {
var agree = confirm('Are you sure?');
if (!agree) return false;
};
</script>
Joe Lencioni
2008-09-29 18:19:16