I would like to know, is it possible to cancel the next JavaScript event in the queue from another event?
Problem:
I have two ASP.Net controls,
Age - TextBox
Save - Button
There are two JavaScript validation functions,
ValidateAge()
- checks for Valid age (0 >= Age <= 140), provides an alert if invalid
ValidatePage()
- checks for all the required fields in the page and saves if all the required fields are filled in
<asp:TextBox ID="txtAge" TabIndex="1" DataType = "String" runat="server" MaxLength="50" CssClass="textBox" Style="width: 150px" CausesValidation="true" onblur="return ValidateAge();"></asp:TextBox>
and there is an access key defined for button,
<asp:Button ID="btnSave" AccessKey="S" AssociatedControlID="btnSave" TabIndex="1" runat="server" CssClass="ButtonSaveNew" onclick="return ValidatePage();"></asp:Button>
Now if I press Alt+S with an invalid age in the Age field first the onblur
of Age gets called (as I have set the AssociatedControlID
) and then the onclick
of the save button is called.
Now what happens is that irrespective of the age is valid or invalid the save gets executed.
I need to cancel the onclick
event of button from the onblur
event of the textbox, if the age is not valid.