使用asp.net按钮控件的jquery

时间:2014-03-14 18:37:22

标签: javascript jquery asp.net

我必须在我的asp.net注册表单中的按钮,一个是提交,另一个是取消,我使用jquery进行表单验证但问题是它弹出即使我点击cancle按钮,我只想要jquery验证提交时,我该怎么办? 这是代码!!谢谢.. :))

<%@ Page Title="" Language="C#" MasterPageFile="~/MAIN.master" AutoEventWireup="true" CodeFile="Registration.aspx.cs" Inherits="Registration" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="templatemo_menu_panel">
        <div id="templatemo_menu_section" style="font-size:xx-large">
           <ul style="padding-top:0px">
                <li><a href="Home.aspx">Home</a></li>
                <li><a href="#">Services</a>
                <ul>
                    <li><a href="Connection.aspx">Connection</a></li>
                    <li><a href="Complaint.aspx">Complaint</a></li>
                </ul>
                </li>
                <li><a href="Registration.aspx" class="current">Registration</a></li>
                <li><a href="Feedback.aspx">Feedback</a></li> 
                <li><a href="#">About US</a></li>     
            </ul>  
        </div>
     </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("#form1").validationEngine();
    });
</script>
<%--<script type="text/javascript">
    function ValidationReg() {
        var str = " ";
        var fname = document.getElementById("ContentPlaceHolder2_txtfnm").value;
        var lname = document.getElementById("ContentPlaceHolder2_txtlnm").value;
        var uname = document.getElementById("ContentPlaceHolder2_txtunm").value;
        var age = document.getElementById("ContentPlaceHolder2_txtage").value;
        if (fname == "") {
            //fna.style.color = color.Red;
            document.getElementById("ContentPlaceHolder2_lblvalfnm").value = "";
            document.getElementById("ContentPlaceHolder2_lblvalfnm").focus();
            alert("first name req");
            return false;
        }
        if (lname == "") {
            document.getElementById("ContentPlaceHolder2_lblvallnm").value = "";
            document.getElementById("ContentPlaceHolder2_lblvallnm").focus();
            alert("last name req");
            return false;
    }
//    else if (uname == "") {
//        alert("UNAME REQ");
//        return false;
//    }
//    if (age == "") {
//        str = str + "AGe required";
//    } 

    if (str == "" && lblfnm=="") {
        return true;
    }
    else {
        return false;
    }    

     }
</script>--%>
<div id="templatemo_content_container">
<div id="templatemo_content">

<div id="wrapper" style="width:1410px">
    <br /><br />
  <table align="center" style="text-align:left">
  <tr><td>
  <asp:Label ID="ldlsuccess" runat="server" Text="" Visible="false" ForeColor="Black" Font-Size="Large"></asp:Label></td></tr>
  <tr><td></td></tr>
  <tr><td></td></tr>
   <tr>
    <th>
        <asp:Label ID="Label12" runat="server" Text="Registration Form" Font-Underline="True" Font-Bold="True" Font-Italic="True" Font-Size="X-Large"></asp:Label>
    </th>
   </tr>  
    <tr><td></td></tr>
    <tr><td></td></tr>
    <tr><td></td></tr> 
    <tr><td></td></tr>
    <tr><td></td></tr>
    <tr><td></td></tr> 
    <tr><td></td></tr>
    <tr><td></td></tr>
    <tr><td>
    <asp:Label ID="Label1" runat="server" Text="First Name"></asp:Label></td>
        <td>
            <asp:TextBox ID="txtfnm" runat="server" CssClass="validate[required]" ></asp:TextBox></td><td></td>
            <td> <asp:Label ID="lblvalfnm" runat="server" Text="" ForeColor="Red"></asp:Label></td>
        </tr>
       <tr><td></td></tr>

        <tr><td>
            <asp:Label ID="Label2" runat="server" Text="Last name"></asp:Label></td>
            <td>
                <asp:TextBox ID="txtlnm" runat="server" CssClass="validate[required]"></asp:TextBox></td><td></td>
            <td> <asp:Label ID="lblvallnm" runat="server" Text="" ForeColor="Red"></asp:Label></td>
            </tr>
              <tr><td></td></tr>

            <tr><td>
                <asp:Label ID="Label3" runat="server" Text="User Name"></asp:Label></td>
                <td>
                    <asp:TextBox ID="txtunm" runat="server" AutoPostBack="True" 
                        ontextchanged="txtunm_TextChanged" CssClass="validate[required]"></asp:TextBox></td>
                        <td>
                            <asp:Label ID="lbluniqueusr" ForeColor="Red" runat="server" Text=""></asp:Label></td><td></td>
            <td> <asp:Label ID="lblvalunm" runat="server" Text="" ForeColor="Red"></asp:Label></td>
                </tr>
                  <tr><td></td></tr>

                  <tr><td>
                      <asp:Label ID="Label4" runat="server" Text="Address"></asp:Label></td>
                     <td>
                         <asp:TextBox ID="txtadd" runat="server" TextMode="MultiLine" CssClass="validate[required]"></asp:TextBox></td><td></td>
            <td> <asp:Label ID="lblvaladd" runat="server" Text="" ForeColor="Red"></asp:Label></td> 
                      </tr>
                      <tr><td></td></tr>
                      <tr><td>
                          <asp:Label ID="Label9" runat="server" Text="Pincode"></asp:Label>
                      </td>
                      <td>
                          <asp:TextBox ID="txtpin" runat="server" CssClass="validate[required]"></asp:TextBox>
                      </td>
                      <td></td>
            <td> <asp:Label ID="lblvalpin" runat="server" Text="" ForeColor="Red"></asp:Label></td>
                      </tr>
                   <tr><td></td></tr>
                        <tr><td>
                            <asp:Label ID="Label11" runat="server" Text="Age"></asp:Label></td>
                     <td>
                            <asp:TextBox ID="txtage" runat="server" CssClass="validate[required]"></asp:TextBox></td><td></td>
            <td> <asp:Label ID="lblvalage" runat="server" Text="" ForeColor="Red"></asp:Label></td>
                       </tr>
                       <tr><td></td></tr>
                    <tr><td>
                        <asp:Label ID="Label5" runat="server" Text="Email"></asp:Label></td>
                        <td>
                            <asp:TextBox ID="txtemail" runat="server" CssClass="validate[required]"></asp:TextBox></td><td></td>
            <td> <asp:Label ID="lblvalemail" runat="server" Text="" ForeColor="Red"></asp:Label></td>
                        </tr>
                          <tr><td></td></tr>

                          <tr><td>
                              <asp:Label ID="Label6" runat="server" Text="Password"></asp:Label></td>
                              <td>
                                  <asp:TextBox ID="txtpass" runat="server" CssClass="validate[required]"></asp:TextBox></td><td></td>
            <td> <asp:Label ID="lblvalpass" runat="server" Text="" ForeColor="Red"></asp:Label></td>
                               </tr>
                                 <tr><td></td></tr>

                               <tr><td>
                                   <asp:Label ID="Label7" runat="server" Text="Confirm Password"></asp:Label></td>
                                   <td>
                                       <asp:TextBox ID="txtcnfpass" runat="server" CssClass="validate[required]"></asp:TextBox></td><td></td>
            <td> <asp:Label ID="lblvalcnfpass" runat="server" Text="" ForeColor="Red"></asp:Label></td>
                                   </tr>
                                     <tr><td></td></tr>
                                     <tr><td>
                                         <asp:Label ID="Label8" runat="server" Text="City"></asp:Label></td>
                                        <td>
                                            <asp:DropDownList ID="ddlcity" runat="server" CssClass="validate[required]">
                                            </asp:DropDownList>
                                        </td><td></td>
            <td> <asp:Label ID="lblvaldllct" runat="server" Text="" ForeColor="Red"></asp:Label></td>
                                        </tr>
                                         <tr><td></td></tr>

                                           <%--<tr><td>
                                               <asp:Label ID="Label9" runat="server" Text="Area"></asp:Label> </td>
                                               <td>
                                                   <asp:DropDownList ID="ddlarea" runat="server">
                                                   </asp:DropDownList>
                                               </td>
                                               </tr>
                                           --%>      <tr><td></td></tr>

                                                   <tr><td>
                                                       <asp:Label ID="Label10" runat="server" Text="Contact No.(Mob)"></asp:Label></td>
                                                      <td>
                                                          <asp:TextBox ID="txtcno" runat="server" CssClass="validate[required]"></asp:TextBox></td> <td></td>
            <td> <asp:Label ID="lblvalcno" runat="server" Text="" ForeColor="Red"></asp:Label></td>
                                                       </tr>
                                                         <tr><td></td></tr>

    </table>
    <br /><br /><br />
    <table align="center">
            <tr>
            <td>
                <asp:Button ID="btnSubmit" CssClass="styled-button-1"  runat="server"
                    Text="Submit" onclick="btnSubmit_Click" />
            </td>
             <td></td>
             <td>
                 <asp:Button ID="btncncl" CssClass="styled-button-1" runat="server" 
                     Text="Cancle" onclick="btncncl_Click" /></td>
            </tr>
            <tr><td></td></tr>
            <tr><td></td></tr> <tr><td></td></tr>
            <tr><td></td></tr>                                                
            </table>
            <br />
</div>
</div>
</div>
</asp:Content>

1 个答案:

答案 0 :(得分:0)

查看此帖子:jQuery Validation plugin: disable validation for specified submit buttons

显然,您只需要在取消按钮中添加cancel的CSS类。

您可以按以下代码添加该类:

<asp:Button ID="btncncl" CssClass="styled-button-1 cancel" runat="server" 
                 Text="Cancel" onclick="btncncl_Click" />

(另外,不确定你是否注意到取消按钮文字的拼写错误,以前是“Cancle”)