Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Custom Validator function with Button on Client Click - Javascript

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!