Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.net验证无火_C#_Asp.net_Validation - Fatal编程技术网

C# ASP.net验证无火

C# ASP.net验证无火,c#,asp.net,validation,C#,Asp.net,Validation,我不知道为什么我的验证不起作用,因为当我点击创建按钮时,页面只是刷新,即使我的字段没有输入任何值。但当我在用户名字段中输入值时,调节器甚至会出现 <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="createmember.aspx.cs" Inherits="member" %> <asp:Content ID="Content1" Co

我不知道为什么我的验证不起作用,因为当我点击创建按钮时,页面只是刷新,即使我的字段没有输入任何值。但当我在用户名字段中输入值时,调节器甚至会出现

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="createmember.aspx.cs" Inherits="member" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <script type="text/javascript">
         $(document).ready(function () {
                $("#MainContent_username").change(function () {
                    var uname = $("#MainContent_username");
                    var msgbox = $("#status");
                    if (uname.val().length < 6) {
                        msgbox.html('<font color="#cc0000">User Name must be more than 5 characters</font>');
                    } else {
                        $.ajax({
                            type: "POST",
                            url: "createmember.aspx/DoesUserExist",
                            data: "{'username': '" + uname.val() + "'}",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (msg) {
                                if (msg.d == false) {
                                    msgbox.html('<font color="Green">User Name Available </font>');
                                }
                                else {
                                    msgbox.html('<font color="Red">User Name Exist</font>');
                                }
                            }
                        });
                    }
                });
            });
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
        <h2>
            Create Member</h2>

        <fieldset>
            <div id="createform">
                <div class="formlabel">
                    Login Name :</div>
                <asp:TextBox ID="username" runat="server"></asp:TextBox>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                    ControlToValidate="username" ErrorMessage="RegularExpressionValidator" 
                    SetFocusOnError="True"></asp:RegularExpressionValidator>
                <span id="usernameempty"></span>
                <span id="status"></span>
                <br />
                <div class="formlabel">
                    Password :</div>
                <asp:TextBox ID="password" runat="server" TextMode="Password"></asp:TextBox>
                <br />
                <div class="formlabel">
                    First Name :</div>
                <asp:TextBox ID="firstname" runat="server"></asp:TextBox>
                <br />
                <div class="formlabel">
                    Last Name :</div>
                <asp:TextBox ID="lastname" runat="server"></asp:TextBox>

                <br />
                <div class="formlabel">
                    Email :</div>
                <asp:TextBox ID="email" runat="server"></asp:TextBox>
                <br />
                <div class="formlabel">
                    User Role :</div>
                <asp:DropDownList ID="role" runat="server">
                    <asp:ListItem Value="2">Admin</asp:ListItem>
                    <asp:ListItem Value="3">Staff</asp:ListItem>
                    <asp:ListItem Value="4">Driver</asp:ListItem>
                    <asp:ListItem Value="5">Manager</asp:ListItem>
                    <asp:ListItem Value="1">Super Admin</asp:ListItem>
                </asp:DropDownList>
                <br />
                <asp:Button ID="submit" runat="server" Text="Create" OnClick="submit_Click" />
                <br />
                <asp:Label ID="msg" runat="server" Text=""></asp:Label>
                <div style="clear: both;" />
            </div>
        </fieldset>
    </asp:Content>

如果输入控件为空,则验证成功。如果关联的输入控件需要值,则除了RegularExpressionValidator控件外,还应使用RequiredFieldValidator控件


似乎验证组出现问题。。。如果您需要验证按钮上的任何控件,请单击该控件,验证程序和按钮应位于同一组,因此,如果您将以下内容用于文本框、验证程序和按钮,我希望它能解决您的问题

 <asp:TextBox ID="username" ValidationGroup="group1" runat="server"></asp:TextBox>
 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
       ControlToValidate="username" ValidationGroup="group1" ErrorMessage="RegularExpressionValidator" 
                SetFocusOnError="True">
</asp:RegularExpressionValidator>
............
<asp:Button ID="submit" runat="server" ValidationGroup="group1" Text="Create" OnClick="submit_Click" />

............

RegularExpressionValidator需要做什么
 <asp:TextBox ID="username" ValidationGroup="group1" runat="server"></asp:TextBox>
 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
       ControlToValidate="username" ValidationGroup="group1" ErrorMessage="RegularExpressionValidator" 
                SetFocusOnError="True">
</asp:RegularExpressionValidator>
............
<asp:Button ID="submit" runat="server" ValidationGroup="group1" Text="Create" OnClick="submit_Click" />