强制将asp:RequiredFieldValidator在GridView中触发一个字段,该字段从禁用更改为启用 [英] Force asp:RequiredFieldValidator to fire in a GridView for a field which is changed from disabled to enabled

查看:46
本文介绍了强制将asp:RequiredFieldValidator在GridView中触发一个字段,该字段从禁用更改为启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:
Gridview的项目只有在第一个字段的下拉菜单设置为特定值(称为此字段1)的情况下才应启用.首先,禁用textBoxField1和dropdownList1.如果设置了field1值,则会在后面的代码中启用textBoxField1和dropdownList1.如果未填充textBoxField1且单击添加"链接按钮时未在dropdownList1中选择任何内容,则上述每个选项的asp:RequiredFieldValidator均不会显示错误,并且asp:CustomValidator不会触发. (看起来合理的是asp:CustomValidator不触发.)

添加链接按钮:

Scenario:
Gridview has items which should only be enabled if first field''s dropdown is set to a specific value (call this field1). To start, textBoxField1 and dropdownList1 are disabled. If field1 value is set, textBoxField1 and dropdownList1 are enabled in the code behind. If textBoxField1 is not filled in and nothing is selected in dropdownList1 when Add linkButton is clicked, the asp:RequiredFieldValidator for each of these does not show an error and the asp:CustomValidator does not fire. (It seems reasonable the asp:CustomValidator does not fire.)

The Add linkButton:

<FooterTemplate>
  <asp:LinkButton ID="AddLink" ValidationGroup="AddValidationGroup" runat="server"  CausesValidation="True" CommandName="Add" ToolTip="Add" >
<asp:Image ID="AddImage" runat="server" ImageUrl="~/Images/Add.png" />
  </asp:LinkButton>
</FooterTemplate>


问题:
如何导致asp:RequiredFieldValidator触发?

预先感谢您的帮助.


Question:
How do I cause the asp:RequiredFieldValidator to fire?

Thank you in advance for your help.

推荐答案

in LinkButton set one property OnClientClick="return validateFields();"
add following function in  <script type="text/javascript"> block of your .aspx page
Here i assume that drop down name is Dropdown1 & RequiredFieldValidators Name is RequiredFieldValidator1 & RequiredFieldValidator1..
Make in appropropriate changes as per your naming..

 function validateFields(){
    var varBool = true;
    var isempty=


get('<% = Gridview1.FindControl(" DropDown1").ClientID
get('<%= Gridview1.FindControl("DropDown1").ClientID %>').value if(isempty != ""){ if (


get('<% = Gridview1.FindControl(" RequiredFieldValidator1").ClientID
get('<%= Gridview1.FindControl("RequiredFieldValidator1").ClientID %>') != null) { var validator =


这篇关于强制将asp:RequiredFieldValidator在GridView中触发一个字段,该字段从禁用更改为启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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