JQuery Validation在asp.net中的母版页上不起作用

本文关键字:母版页 不起作用 net Validation asp JQuery | 更新日期: 2023-09-27 18:23:56

我有一些带有一个母版页的.aspx页面。我想对.aspx页面上的所有控件进行客户端验证。为此,我使用jquery验证。(ashley在papermashup.com教程上验证的番茄酱插件)

它在.aspx页面"Without"母版页上正常工作。但是当我使用相同的代码&链接母版页上的文件,则它不起作用。

无主页的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="validation_demo.aspx.cs" Inherits="webpages_validation_demo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" media="screen" href="../css/jquery.ketchup.css" />
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.ketchup.js"></script>
<script type="text/javascript" src="../js/jquery.ketchup.messages.js"></script>
<script type="text/javascript" src="../js/jquery.ketchup.validations.basic.js"></script>
<link rel="shortcut icon" href="../../Styles/favicon.ico" />
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link href="../CSS/jquery.ketchup.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/style.css" rel="stylesheet" type="text/css" />
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="../CSS/style_menu.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/Form_style.css" rel="stylesheet" type="text/css" />
     <link href="../CSS/StyleSheet2.css" rel="stylesheet" type="text/css" />
   <script type="text/javascript" src="../../image/jquery.js"></script> 
    <link href="../CSS/modalbox.css" rel="stylesheet" type="text/css" />
    <script src="../Js/CommonFunctions.js" type="text/javascript"></script>
    <script src="../Js/CommonValidations.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#signup').ketchup();
    });
</script>
</head>
<body>
   <form action="" runat="server" method="post" id="signup">
    <div style="margin-left:300px;margin-top:50px;">
          <input type="text" class="validate(required ,number, minlength(10) ,maxlength(10))"  name="number" />
    </div>
    </form>
</body>
</html>

带母版页的代码:

主页:

 <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Master_demo.master.cs" Inherits="webpages_Master_demo" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <asp:ContentPlaceHolder id="head" runat="server">
        </asp:ContentPlaceHolder>
          <link rel="stylesheet" type="text/css" media="screen" href="../css/jquery.ketchup.css" />
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.ketchup.js"></script>
    <script type="text/javascript" src="../js/jquery.ketchup.messages.js"></script>
    <script type="text/javascript" src="../js/jquery.ketchup.validations.basic.js"></script>
    <link rel="shortcut icon" href="../../Styles/favicon.ico" />
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <link href="../CSS/jquery.ketchup.css" rel="stylesheet" type="text/css" />
        <link href="../CSS/style.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="../CSS/style_menu.css" rel="stylesheet" type="text/css" />
        <link href="../CSS/Form_style.css" rel="stylesheet" type="text/css" />
         <link href="../CSS/StyleSheet2.css" rel="stylesheet" type="text/css" />
       <script type="text/javascript" src="../../image/jquery.js"></script> 
        <link href="../CSS/modalbox.css" rel="stylesheet" type="text/css" />
        <script src="../Js/CommonFunctions.js" type="text/javascript"></script>
        <script src="../Js/CommonValidations.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#signup').ketchup();
        });
    </script>
    </head>
    <body>
  <form action="" runat="server" method="post" id="signup">   
        <div>
            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">        
            </asp:ContentPlaceHolder>
        </div>  
</form> 
    </body>
    </html>
aspx pge with master page:
    <%@ Page Title="" Language="C#" MasterPageFile="~/webpages/Master_demo.master" AutoEventWireup="true" CodeFile="demo_validation1.aspx.cs" Inherits="webpages_demo_validation1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript">
        $(document).ready(function () {
            $('#signup').ketchup();
        });
    </script>
    <div style="margin-left:300px;margin-top:50px;">
              <input type="text" class="validate(required ,number, minlength(10) ,maxlength(10))"  name="number" /> 
     </div>
    </asp:Content>

JQuery Validation在asp.net中的母版页上不起作用

我认为您的主页面上缺少ID为注册的表单元素

--更新

OK

将您的输入更改为以下

 <input type="text" data-validate="validate(required ,number, minlength(10) ,maxlength(10))"  name="number" /> 

在这里重新下载番茄酱插件

https://github.com/mustardamus/ketchup-plugin/downloads

并使用以下线路

<script type="text/javascript" src="js/jquery.ketchup.all.min.js"></script>

而不是

<script type="text/javascript" src="../js/jquery.ketchup.js"></script>
    <script type="text/javascript" src="../js/jquery.ketchup.messages.js"></script>
    <script type="text/javascript" src="../js/jquery.ketchup.validations.basic.js"></script>

这对我有用。