martes, 25 de junio de 2013

JQuery Validator plugin


1) This line include JQuery to your project
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2..2/jquery.min.js"></script>

2) This line include JQuery Validator to your project in .Net
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js"></script>

3) In your .aspx file write the next jscript code to validate the empty fields
   #ctl01 is the Id Form
   #MainContent_btn222  is the Id Button


$(document).ready(function () {
    // Initialize validation on the entire ASP.NET form

    $("#ctl01").validate({
        // This prevents validation from running on every
        //  form submission by default.
        onsubmit: false
    });

    $("#MainContent_btn222").click(function (evt) {
        // Validate the form and retain the result.
        var isValid = $("#ctl01").valid();

        // If the form didn't validate, prevent the
        //  form submission.
        if (!isValid)
            evt.preventDefault();
    });
});

4) In your fields add the tag CssClass with the value required

<asp:TextBox ID="To" runat="server" Width="350px" CssClass="required"/>

No hay comentarios:

Publicar un comentario