简体   繁体   English

下拉列表所需的字段验证器不起作用

[英]required field validator for dropdown list not working

Need your help.需要你的帮助。 I am trying to validate drop down list using RequiredField Validator.我正在尝试使用 RequiredField Validator 验证下拉列表。 If user has not selected any value then it should show error.如果用户没有选择任何值,那么它应该显示错误。 However i am not able to achieve this task.但是我无法完成这项任务。

ASPX code: ASPX 代码:

<asp:dropdownlist id="ddlSPOC" runat="server" 
     skinid="SkDrpLst" width="210px" height="22px" 
     AppendDataBoundItems="True" validationgroup="Validation">
</asp:dropdownlist>

<asp:requiredfieldvalidator id="rfvddlSPOC" runat="server" 
     controltovalidate="ddlSPOC" InitialValue="0" 
     errormessage="*Please Select SPOC" enabled="false" 
     ForeColor="Red"></asp:requiredfieldvalidator>

Any Help would be appreciated.任何帮助,将不胜感激。

Note: I have 7-8 controls on same page and RFV working properly for them.注意:我在同一页面上有 7-8 个控件,并且 RFV 可以为它们正常工作。

I think you should remove initialvalue=0 like below code我认为你应该像下面的代码一样删除 initialvalue=0

<asp:requiredfieldvalidator id="rfvddlSPOC" runat="server" 
 controltovalidate="ddlSPOC" 
 errormessage="*Please Select SPOC" enabled="true" 
 ForeColor="Red"></asp:requiredfieldvalidator>

because we are already assigning the value so it is reading as value.因为我们已经在分配值,所以它正在读取值。 Might be thats why validation is not working.可能这就是验证不起作用的原因。 Please try and let me know.请尝试让我知道。

Thanks :)谢谢 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM