下拉列表和字段验证引发骚乱
由于某种原因,当我做错事情时,我无法让验证器举起标志。
下拉列表有很好的值,包括初始虚拟值。
都不是
也不是
提出任何标志说“嘿 - 你搞砸了,去修复它”。对于所有的谷歌、搜索、评论、挥舞大锤子,我还没有发现我做错了什么。
我只想要一种解决方案来解决所有问题。
哦,是的,我在 DDL、RFV/CV 和按钮之间还有一个 ValidationGroup="myGroup"
。运气不好。
For some reason, I can't get the validator to raise a flag when I do things wrong.
<asp:DropDownList ID="ddlTypeList" runat="server" DataSourceID="ods_TypeOptions" DataTextField="name" DataValueField="id" SelectedValue='<%# Bind("Type") %>' AppendDataBoundItems="true">
<asp:ListItem Text="-" Value="-1" Selected="True"></asp:ListItem>
</asp:DropDownList>
The drop down list has nice values, incl the initial dummy.
Neither
<asp:RequiredFieldValidator ID="rfw" runat="server" ControlToValidate="ddlTypeList"
InitialValue="-1" ToolTip="Required">*</asp:RequiredFieldValidator>
Nor
<asp:CompareValidator ID="cv" runat="server" ControlToValidate="ddlTypeList" ValueToCompare="-1" Operator="NotEqual" ToolTip="Required">*</asp:CompareValidator>
Raises any flags to say "hey - u messed up, go fix it". For all the google, searching, reviews, swinging big hammers, I have yet to spot what I am doing wrong.
I just want one solution to fix them all.
Oh yes, I also had a ValidationGroup="myGroup"
between the DDL, RFV/CV and the button. No luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码是正确的。您必须有某些代码或标记元素阻碍验证器的功能。是否有可能“-”项的
值
从“-1”更改为其他值?验证提交表单的按钮是否具有
CausesValidation=True
。此外,请确保验证器的父级未设置为Visible=False
,否则子级将不会呈现在页面上。通过在输出的标记中搜索“_cv”或可能的“cv”,验证
RequiredFieldValidator
和CompareValidator
是否在标记中呈现。如果它不存在,则父元素之一不会被渲染或者验证器将被删除。Your code is correct. You must have some element of code or markup that is obstructing the functionality of the validator. Is it possibly that the "-" item has its
value
changed from "-1" to something else?Verify that your button that submits the form has
CausesValidation=True
.Also, make sure that the parent of the validators is not set toVisible=False
or the children will not render on the page.Verify that the
RequiredFieldValidator
andCompareValidator
are rendering in the markup by searching for "_cv" or possibly "cv" in the outputted markup. If it is not there, then one of the parent elements is not being rendered or the validators are being deleted.