Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda