向导控件验证问题中用户控件中的自定义验证器

发布于 2024-08-14 13:26:15 字数 1428 浏览 2 评论 0原文

我有一个复选框位于用户控件中,用户控件位于向导控件中,而向导控件位于具有母版页的内容页上。

在向导控件完成之前必须选中该复选框。复选框和自定义验证器位于向导控件的最后一步。

现在 Firefox 一切正常,当我用 IE 测试时也一切正常。但不知何故,其他人可能能够继续该过程,而不必选中该复选框。 该复选框还有一个切换按钮扩展器。我希望这不是问题。

我的内联javascript(在用户控件中)

<script language="javascript" type="text/javascript">
    // <![CDATA[
    function ValidateTandCs(source, args)
    {
        args.IsValid = document.getElementById('<%= cbAV.ClientID %>').checked;
    } 
    // ]]>
</script> 

复选框:

<asp:checkbox id="cbAV" runat="server"/>

customevalidator和切换按钮扩展程序

<asp:CustomValidator 
     ID="rfvAV" 
     Display="Dynamic" 
     runat="server" 
     ControlToValidate="cbAV" 
     ErrorMessage="RequiredFieldValidator" 
     ClientValidationFunction="ValidateTandCs" 
     onservervalidate="rfvAV_ServerValidate">
</asp:CustomValidator>
<ajaxToolkit:ToggleButtonExtender 
     ID="tbeav" 
     runat="server" 
     TargetControlID="cbAV" 
     ImageHeight="15" 
     ImageWidth="15" 
     CheckedImageUrl="~/images/checkbox-on.gif" 
     UncheckedImageUrl="~/images/checkbox-off.gif" />

customvalidator背后的代码

protected void rfvAV_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = (cbAV.Checked);
}

我尝试从customvalidator中删除客户端验证,但是当我只有服务器验证时。它不起作用

i have a checkbox which is in a usercontrol and the usercontrol is in an wizardcontrol and the wizardcontrol is on a content page which has a masterpage.

the checkbox must be checked before the wizard controls finishes. the checkbox and the customvalidator are on the last step of the wizardcontrol.

now everything works fine with firefox and when i test it also with ie. but somehow other people may be able to go on with the proces without having to check the checkbox.
the checkbox also has a togglebutton extender. i hope that that is not a problem.

my inline javascript (in the usercontrol)

<script language="javascript" type="text/javascript">
    // <![CDATA[
    function ValidateTandCs(source, args)
    {
        args.IsValid = document.getElementById('<%= cbAV.ClientID %>').checked;
    } 
    // ]]>
</script> 

the checkbox:

<asp:checkbox id="cbAV" runat="server"/>

the customevalidator and togglebutton extender

<asp:CustomValidator 
     ID="rfvAV" 
     Display="Dynamic" 
     runat="server" 
     ControlToValidate="cbAV" 
     ErrorMessage="RequiredFieldValidator" 
     ClientValidationFunction="ValidateTandCs" 
     onservervalidate="rfvAV_ServerValidate">
</asp:CustomValidator>
<ajaxToolkit:ToggleButtonExtender 
     ID="tbeav" 
     runat="server" 
     TargetControlID="cbAV" 
     ImageHeight="15" 
     ImageWidth="15" 
     CheckedImageUrl="~/images/checkbox-on.gif" 
     UncheckedImageUrl="~/images/checkbox-off.gif" />

the code behind of the customvalidator

protected void rfvAV_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = (cbAV.Checked);
}

i have tried to remove the clientside validation from the customvalidator, but when i only have the server validation. it doesn't work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

才能让你更想念 2024-08-21 13:26:15

为什么要在客户端和服务器端同时使用验证例程?

尝试删除 ClientValidationFunction 属性并保留 OnServerValidate 属性。

Why are you using both a validation routine on the client side and one on the server side?

Try removing the ClientValidationFunction property on your and keep the OnServerValidate property.

北笙凉宸 2024-08-21 13:26:15

发现了问题。这是因为 javascript(客户端)在 IE 中不起作用。
服务器端验证,验证确实不错。但是当您单击向导控件的完成按钮时,它没有进行 page.isvalid 检查。所以它只是忽略了无效的验证器。我的错。

found the problem. it was that the javascript (clientside) didn't work in IE.
the serverside validation, validated really good. but when you click on the finishbutton of the wizard control it didn't had a page.isvalid check. so it just ignored the invalid validator. my bad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文