Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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 - Fatal编程技术网

C# asp.net中的客户端验证

C# asp.net中的客户端验证,c#,asp.net,C#,Asp.net,我正在尝试使用customvalidator创建必需的字段验证。但是,当字段为空时,它仍然进行回发 <body> <form id="Form1" runat="server"> <h3> CustomValidator ServerValidate Example</h3> <asp:Label ID="Message" Font-Name="Verdana" Font-Size="10pt" run

我正在尝试使用customvalidator创建必需的字段验证。但是,当字段为空时,它仍然进行回发

<body>
    <form id="Form1" runat="server">
    <h3>
        CustomValidator ServerValidate Example</h3>
    <asp:Label ID="Message" Font-Name="Verdana" Font-Size="10pt" runat="server" />
    <p>
        <asp:TextBox ID="Text1" runat="server" Text="[Name:required]" />
        &nbsp;&nbsp;
        <asp:CustomValidator ID="CustomValidator1" ControlToValidate="Text1" ClientValidationFunction="ClientValidate"
            Display="Static" ErrorMessage="" ForeColor="green" Font-Name="verdana" Font-Size="10pt"
            runat="server" />
        <p>
            <asp:Button ID="Button1" Text="Validate" OnClick="ValidateBtn_OnClick" runat="server" />
    </form>
</body>
</html>
<script language="javascript">
    function ClientValidate(source, arguments) {
        alert(arguments.Value.length);
        if (arguments.Value != "[Name:required]" && arguments.Value.length > 0) {
            arguments.IsValid = true;
        } else {
            arguments.IsValid = false;
        }
    }
</script>

CustomValidator服务器验证示例


函数ClientValidate(源、参数){
警报(arguments.Value.length);
if(arguments.Value!=“[名称:必需]”&&arguments.Value.length>0){
arguments.IsValid=true;
}否则{
arguments.IsValid=false;
}
}

ValidateEmptyText=“True”
添加到CustomValidator标签中


有关更多详细信息,请参阅。

您应该将包含ClientValidate函数的
标记移动到
标记内,最好是移动到
标记内。

尝试在文本框和按钮上使用
验证组
验证组=“MyValidationGroup”
。您还可以在按钮上设置
CausesValidation=true
属性。