当 ControlToValidate 可见性更改时,RequiredFieldValidator 不会触发
当我更改 ddl.Visible=true(它在另一个表单元素事件的部分回发/更新面板上更改)时,RequiredFieldValidator 将不会触发?
注意:这不是正常情况下如何使用RequiredFieldValidator的问题。 我的表单具有级联下拉菜单,这些下拉菜单都是动态构建的,其可见性可以打开和关闭。
<asp:DropDownList ID="ddl" Visible="false" AutoPostBack="True" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="ddl"
ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Required"></asp:RequiredFieldValidator>
When I change ddl.Visible=true(it gets changed on partial postback/updatepanel from another form element event)the RequiredFieldValidator will not fire?
NOTE: This is not a question on how to use the RequiredFieldValidator in a normal circumstance. My form has cascading dropdowns that are all dynamically built with their visibility toggled on and off.
<asp:DropDownList ID="ddl" Visible="false" AutoPostBack="True" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="ddl"
ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Required"></asp:RequiredFieldValidator>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要设置
属性,以便它知道RequiredFieldValidator
上的 InitialValueDropDownList
的值何时发生更改。 例如,在具有以下值的下拉列表中:您可以将此属性添加
到您的
RequiredFieldValidator
中。如果不知道值是否已更改,验证器就不可能知道用户是否满足其要求。
You need to set the
InitialValue
property on yourRequiredFieldValidator
so that it knows when the value of theDropDownList
has changed. For example, on a dropdown with these values:You would add this attribute
to your
RequiredFieldValidator
.Without knowing if the value has changed it is impossible for the validator to know whether or not the user has satisfied its requirement.