How can I cancel a client side server control event?
3 answers
<asp:ImageButton OnClientClick="return ValidatorOnSubmit()" />
The ValidatorOnSubmit () function should already be enabled by the ASP.NET framework if you have validators on your form. The standard onsubmit WebForm function looks like this:
function WebForm_OnSubmit() {
if ( typeof(ValidatorOnSubmit) == "function"
&& ValidatorOnSubmit() == false) return false;
return true;
}
+1
source to share
There is an OnClientClick event that you can set for your javascript function. If you return it will continue until the post office. If you return false, no message appears.
<asp:Button ID="NavigateAway" runat="server" OnClientClick="javascript:return PromptToNavigateOff();" OnClick="NavigateAwayButton_Click" Text="Go Away" />
<script type="text/javascript">
function PromptToNavigateOff()
{
return confirm("Are you sure you want to continue and loose all your changes?");
}
</script>
0
source to share