Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
Stop function through JavaScript

I have this js function :

function neki() {
  if ( $("input[id*='txtIDCriteria']").val() == ''
    && $("input[id*='chkID']").is(':checked')
  ) {
    alert('Value is required.');
  }
}

And this asp code:

<table border="0" cellpadding="1" cellspacing="0"
  style="width: 100%" class="DataTable" id="check_all"
>
  <tr>
    <td>
      <asp:CheckBox CssClass="formdata100" ID="chkID" runat="server"> 
      </asp:CheckBox>
    </td>
    <td>
      <asp:Label CssClass="formdata100" ID="lblID" runat="server">
        Maintenance ID
      </asp:Label>
    </td>
    <td>
      <asp:TextBox CssClass="formdata100" ID="txtIDCriteria"
        runat="server" MaxLength="6"
        onkeyup="return validate_int(event,this);"
      >
      </asp:TextBox>
    </td>
  </tr>
  <tr>
    <td colspan="5">
      <asp:Button Text="search" ID="search" OnClick="search_Click"
        runat="server" style="float:right" onClientClick="neki()"
      />
    </td>
  </tr>

I want this OnClick="search_Click" to stop when this function neki() is executed ie when it is true.

How to solve it through JavaScript?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Yes, you can do this. The way this works?

If the onclient click function returns true, then the server side code/event runs.

If the onclient click function returns false, then the server side code/event does NOT run. So you can do this:

   <asp:Button Text="search" ID="search" OnClick="search_Click"
    runat="server" style="float:right" onClientClick="return neki();"

And now your JS code can be this:

function neki() {
    if ( $("input[id*='txtIDCriteria']").val() == ''
        && $("input*[id*='chkID']").is(':checked'))
    {
    alert('Value is required.');
    return true;
    }
    return false;
}

While this will work for above, if you use a jQuery.UI dialog, the code does not wait, but there is a simple work around for even jQuery.UI dialog that respond to say a yes/no answer, and you can still conditional run the server side button code.

edit: opps - I have this backwards.

the code should be like this:

function neki() {
    if ( $("input[id*='txtIDCriteria']").val() == ''
        && $("input*[id*='chkID']").is(':checked'))
    {
    alert('Value is required.');
    return false;  <--- return false to NOT run button click
    }
    return true;   <--- return true - this will allow button click to run
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda