-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

rook ....
  • 156
  • 2
  • 14
  • possible duplicate of [jQuery Validation plugin in ASP.NET Web Forms](http://stackoverflow.com/questions/619816/jquery-validation-plugin-in-asp-net-web-forms) – jrummell Apr 24 '12 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 – rook .... Apr 24 '12 at 12:51

1 Answers1

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>
Matthias
  • 7,432
  • 6
  • 55
  • 88
akeeseth
  • 845
  • 2
  • 15
  • 32