RequiredFieldValidator不适用于Dropdownlist [英] RequiredFieldValidator not working for Dropdownlist

查看:64
本文介绍了RequiredFieldValidator不适用于Dropdownlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页中有一个 Dropdownlist ,如下所示.

I have a Dropdownlist in my web page as follows.

<asp:DropDownList runat="server" ID="cboNoOfSubjects" AutoPostBack="true" CssClass="textEntry"  width="80%" onclick="javascript:shouldsubmit=false;" ValidationGroup="valCourseFees">
   <asp:ListItem Value="0">-Select-</asp:ListItem>
   <asp:ListItem Value="1">1</asp:ListItem>
   <asp:ListItem Value="2">2</asp:ListItem>
   <asp:ListItem Value="3">3</asp:ListItem>
   <asp:ListItem Value="4">4</asp:ListItem>
   <asp:ListItem Value="5">5</asp:ListItem>
</asp:DropDownList>
    <font color ="red">*</font> 

<asp:RequiredFieldValidator ID="cboNoOfSubjects_RequiredFieldValidator" 
 runat="server" ErrorMessage="No. of Subjects Required" ForeColor="Red"
 Font-Size="0.9em" ControlToValidate="cboNoOfSubjects" 
ValidationGroup="valCourseFees" Display="None"></asp:RequiredFieldValidator>

但是验证器似乎没有触发.有人可以帮我吗?

But the validator does not seem to fire. Can anyone help me with this?

推荐答案

对于所有RequiredFieldValidators,

For all RequiredFieldValidators, the InitalValue property is important. Add it to yours and it will work.

<asp:RequiredFieldValidator ID="cboNoOfSubjects_RequiredFieldValidator" runat="server"  
 ErrorMessage="No. of Subjects Required" ForeColor="Red" InitialValue="0"
 Font-Size="0.9em" ControlToValidate="cboNoOfSubjects" 
 ValidationGroup="valCourseFees" Display="None"></asp:RequiredFieldValidator>

要更改的另一件事,您必须设置属性Display ="Dynamic",该属性将相应显示.

One thing more to change, you have to set the property Display="Dynamic" which will display accordingly.

这篇关于RequiredFieldValidator不适用于Dropdownlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆