-2

i am new to jquery ; i am using jquery validation as shown below:

    function validate() {
        return $('#aspnetForm').valid();
    }



<asp:Button UseSubmitBehavior="false" ID="Button1" runat="server" Text="Button" OnClientClick="return validate();" OnClick="btnSubmit_Click"></asp:Button>

is this possible in asp.net ?; currently this button is not post backing if function returns true

2
  • possible duplicate of jQuery Validation plugin in ASP.NET Web Forms Commented Apr 24, 2012 at 12:29
  • i change java script to function validate(e) { if ($('#aspnetForm').valid()) { __doPostBack($(e).attr("name"), ""); return true; //proceed } else { return false; //cancel; } } now its working Commented Apr 24, 2012 at 12:51

1 Answer 1

0

You need jQuery library, jQuery Validation plugin and meta plugin.


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://jquery-multifile-plugin.googlecode.com/svn-history/r16/trunk/jquery.MetaData.js"></script>

<form id="form1" runat="server">
    <asp:TextBox ID="txtEmail" runat="server" class="{required:true, email:true,messages:{required:'required.',email: 'invalid email!' }}"></asp:TextBox>
    <!-- ... -->
    <asp:Button ID="btnSubmit" runat="server" Text="submit" />
</form>

Use validate() of jQuery validation plugin on asp.net form.

<script type="text/javascript">
    $(document).ready(function () {
        $("#form1").validate();
    });
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.