向导控件验证问题中用户控件中的自定义验证器
我有一个复选框位于用户控件中,用户控件位于向导控件中,而向导控件位于具有母版页的内容页上。
在向导控件完成之前必须选中该复选框。复选框和自定义验证器位于向导控件的最后一步。
现在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要在客户端和服务器端同时使用验证例程?
尝试删除 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.
发现了问题。这是因为 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.