【问题标题】:Validation asp.net with bootstrap使用引导程序验证 asp.net
【发布时间】:2015-05-23 17:03:20
【问题描述】:

我正在尝试使用 asp.net/bootstrap 制作验证表单。我正在用一个文本框对其进行测试。

目前这是我的代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <script src="Scripts/jquery-1.10.2.min.js"></script>

</head>

  <body>

    <form id="form1" runat="server">
        <asp:TextBox runat="server" CssClass="form-control" ID="userNameTextBox" />
        <input id="Submit1" type="submit" value="submit" />
    </form>

    <script type="text/javascript">
        $(document).ready(function() {
            $('#form1').formValidation({
                framework: 'bootstrap',
                icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    <%=userNameTextBox.UniqueID%>: {
                    validators: {
                        notEmpty: {
                            message: 'The username is required and cannot be empty'
                        },
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: 'The username must be more than 6 and less than 30 characters long'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9]+$/,
                            message: 'The username can only consist of alphabetical and number'
                        },
                        different: {
                            field: 'password',
                            message: 'The username and password cannot be the same as each other'
                        }
                    }
                }
            }
        });
    });
    </script>
</body>
</html>

但是当我点击按钮时,什么也没有发生。我究竟做错了什么??谢谢你的帮助!

【问题讨论】:

标签: jquery asp.net twitter-bootstrap


【解决方案1】:

我知道这有点老了,但你会想要使用 &lt;%=userNameTextBox.ClientID%&gt; 而不是 &lt;%=userNameTextBox.UniqueID%&gt; 来获取生成的 HTML 元素的 ID 以在 javascript 中引用。有关不同 ASP.NET id 值的更多详细信息,请参阅this answer

【讨论】:

    猜你喜欢
    • 2014-06-06
    • 2021-05-20
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    • 1970-01-01
    相关资源
    最近更新 更多