I have a textbox to which I have assigned a CustomValidator which has a ClientValidationFunction=”txtcheck”
ASPX:
<asp:TextBox ID="txt1" MaxLength="10" CssClass="class1" Width="90%" runat="server"></asp:TextBox>
<asp:CustomValidator runat="server" ID="valtxt1" ControlToValidate="txt1" ValidateEmptyText="true" ValidationGroup="Save" Display="Dynamic"
ClientValidationFunction="txtcheck" Font-Italic="True"></asp:CustomValidator>
<asp:Button ID="btnSave" Text="Save" CausesValidation="True" runat="server" ValidationGroup="Save" OnClientClick="show()" UseSubmitBehavior="false" />
Javascript :
The alert messge is mandatory as it is required.
function txtcheck(source, args) {
Alert('incorrect value');
args.IsValid = false;
}
function show(){
var validated = Page_ClientValidate('valSave');
if (validated) {
-- show some data.
}
}
On click of Save Button I do a Page_ClientValidate to check other controls.
The issue is, on click of Save; txtcheck() is getting called twice.
Once via the CustomValidator & other when I do the Page_ClientValidate. Due to this the Alert message is also shown twice.
Pls guide as to how to call the txtcheck() only once & show alert once.
Any help is greatly appreciated.