Is there a way to identify which button was clicked using JavaScript? I have validation in place, but I want it to only validate when a specific button is clicked and not when other controls are interacted with.
PLEASE NOTE THAT I HAVE 3 TEXTBOXES SIMILAR TO THE ONE BELOW. THEY ARE USED FOR ENTERING A PHONE NUMBER SPLIT INTO 3 PARTS.
What I am trying to achieve is to add an '&&' condition in the JavaScript if statement to set args.IsValid to false only when the submit button is clicked. Currently, validation occurs on pressing the tab key or clicking on other controls, but I want it to happen only when the submit button is clicked.
function checkPhoneNumber(sender, args) {
alert(window.event);
if (phnavalue.value != '' || phnevalue.value != '' || phnnvalue.value != '' ) {
if (phnnvalue.value.length < 4) {
args.IsValid = false;
}
else {
ValidatorEnable(RFV2, true);
ValidatorEnable(RFV3, true);
}
}
}
<ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender4" runat="server"
TargetControlID="phnnVal"
HighlightCssClass="validatorCalloutHighlight"
></ajaxToolkit:ValidatorCalloutExtender>
<asp:TextBox ID="witPhnn" runat="server" MaxLength="4" Width="50pt"></asp:TextBox>
<asp:CustomValidator ID="phnNumValn" runat="server"
Display="None"
ControlToValidate="witPhnn"
ErrorMessage="Please enter a valid phone number."
SetFocusOnError="True"
EnableClientScript="true"
ClientValidationFunction="checkPhoneNumber"
></asp:CustomValidator>