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
Javascript 为什么ClientValidationFunction不能正常工作? 函数clientValidation(发送方、参数) { if(arguments.value==“hello world”) arguments.isvalid=true; 其他的 arguments.isvalid=false; 警报(arguments.isvalid); }_Javascript_Asp.net_Validation_Asp.net Mvc Validation - Fatal编程技术网

Javascript 为什么ClientValidationFunction不能正常工作? 函数clientValidation(发送方、参数) { if(arguments.value==“hello world”) arguments.isvalid=true; 其他的 arguments.isvalid=false; 警报(arguments.isvalid); }

Javascript 为什么ClientValidationFunction不能正常工作? 函数clientValidation(发送方、参数) { if(arguments.value==“hello world”) arguments.isvalid=true; 其他的 arguments.isvalid=false; 警报(arguments.isvalid); },javascript,asp.net,validation,asp.net-mvc-validation,Javascript,Asp.net,Validation,Asp.net Mvc Validation,试试这个 <script type="text/javascript"> function clientValidation(sender, arguments) { if (arguments.value == "hello world") arguments.isvalid = true; else arguments.isvalid = false; alert(a

试试这个

<script type="text/javascript">
    function clientValidation(sender, arguments)
    {
        if (arguments.value == "hello world")
            arguments.isvalid = true;
        else
            arguments.isvalid = false;

        alert(arguments.isvalid);
    }
</script>

<asp:Label ID="lblName" runat="server" Text="Enter Your Name" />
<asp:TextBox ID="txtbxName" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="You are Not allowed" Display="None" ClientValidationFunction="clientValidation" ValidationGroup="ValidationSummary1" />
<br />
<asp:Label ID="lblClass" runat="server" Text="Class" />
<asp:TextBox ID="txtClass" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter Clas" ControlToValidate="txtClass" Display="None" ValidationGroup="ValidationSummary1" />
<br />            
<asp:ValidationSummary ValidationGroup="ValidationSummary1" ID="ValidationSummary1" runat="server" />
<br />
<asp:Button ID="Button1" runat="server" Text="Validate" ValidationGroup="ValidationSummary1" />
编辑:设置ControlToValidate属性

function clientValidation(sender, arguments)
{
  if (arguments.Value == "hello world")
     arguments.IsValid = true;
  else
     arguments.IsValid = false;
}

试试这个

<script type="text/javascript">
    function clientValidation(sender, arguments)
    {
        if (arguments.value == "hello world")
            arguments.isvalid = true;
        else
            arguments.isvalid = false;

        alert(arguments.isvalid);
    }
</script>

<asp:Label ID="lblName" runat="server" Text="Enter Your Name" />
<asp:TextBox ID="txtbxName" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="You are Not allowed" Display="None" ClientValidationFunction="clientValidation" ValidationGroup="ValidationSummary1" />
<br />
<asp:Label ID="lblClass" runat="server" Text="Class" />
<asp:TextBox ID="txtClass" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter Clas" ControlToValidate="txtClass" Display="None" ValidationGroup="ValidationSummary1" />
<br />            
<asp:ValidationSummary ValidationGroup="ValidationSummary1" ID="ValidationSummary1" runat="server" />
<br />
<asp:Button ID="Button1" runat="server" Text="Validate" ValidationGroup="ValidationSummary1" />
编辑:设置ControlToValidate属性

function clientValidation(sender, arguments)
{
  if (arguments.Value == "hello world")
     arguments.IsValid = true;
  else
     arguments.IsValid = false;
}


请提出一个问题,而不仅仅是发布代码@El Ronnoco:在上面的代码中,警报框中总是有值false为什么会这样?@Victo:这就是我不理解的地方尝试
参数。值
而不是
参数。值
。Javascript是区分大小写的。请提出一个问题,而不仅仅是发布代码@El Ronnoco:在上面的代码中,警报框中总是有值false为什么会这样?@Victo:这就是我不理解的地方尝试
参数。值
而不是
参数。值
。Javascript区分大小写。感谢您的回答;尝试了代码,但仍然有错误。提前谢谢。它可以工作,但是如果我不使用controltovalidate,为什么它不能工作?@jagdeep,因为CustomValidator需要一些东西来验证。ControlToValidate只验证它所说的,它验证您指定的控件;尝试了代码,但仍然有错误。提前谢谢。它可以工作,但是如果我不使用controltovalidate,为什么它不能工作?@jagdeep,因为CustomValidator需要一些东西来验证。ControlToValidate只执行它所说的,它验证您指定的控件。