• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1612
  • Last Modified:

Disable RequiredFieldValidator in a gridview

Hi,
I would like to implement a client side javacript function to disable the requiredfieldvalidators in my gridview depending on a checkbox outside the Gridview.
I have looked at several example but can't get one work for me. Here is my code

<script language="JavaScript" type="text/javascript">
    function disableRFV()
    {
         ?????      
    }  

<asp:CheckBox ID="ckb" runat="server" OnCheckedChanged="disableRFV();" />

<asp:GridView ID="PackInnGrid" runat="server" CssClass="grid" Width="620px" AutoGenerateColumns="False" DataKeyNames="ProdInnID"
ShowFooter="false" EmptyDataText="No data entered!" EnableViewState="true" Enabled="true">      
<RowStyle CssClass="row" /><AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:BoundField DataField="ProdInnID" Visible="false" />  

<asp:TemplateField HeaderText="PCB">
<ItemStyle Width="30px" />
<ItemTemplate><asp:TextBox ID="txbProdInnP" runat="server" CssClass="rowEdit" Width="30px" />
<asp:RequiredFieldValidator ID="reqInnPCB" runat="server" ControlToValidate="txbProdInnP" ValidationGroup="MyVal"
ErrorMessage="*" Display="Dynamic" EnableViewState="true" />
<asp:RegularExpressionValidator id="ValInnPcb" runat="server" Display="Dynamic"
ControlToValidate="txbProdInnP" ValidationExpression="^[1-9]+[0-9]*$" ErrorMessage="Integer only!"></asp:RegularExpressionValidator>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Length">
<ItemStyle width="60px" />
<ItemTemplate><asp:TextBox ID="txbProdInnL" runat="server" CssClass="rowEdit" Width="60px" />
<asp:RequiredFieldValidator ID="reqInnLength" runat="server" ControlToValidate="txbProdInnL" ValidationGroup="MyVal"
ErrorMessage="*" Display="Dynamic" EnableViewState="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>  
</asp:GridView>

0
pascalmartin
Asked:
pascalmartin
  • 3
  • 2
  • 2
  • +1
1 Solution
 
BurniePCommented:
This should work :

<script language="JavaScript" type="text/javascript">
    function disableRFV()
    {
         Page_ValidationActive = false;
    }  


0
 
devlab2012Commented:
You can use ValidatorEnable function, like below:

ValidatorEnable(RequiredFieldValidator1, false);

and then call ValidatorValidate(), because the validator is disabled in above line, so it will always pass the validation test.
ValidatorValidate(RequiredFieldValidator1);
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
meispiscesCommented:
Is your problem resolved? Let me know your comments
0
 
pascalmartinAuthor Commented:
meispisces: I have seen the forum but it does not respond to what I need.
0
 
pascalmartinAuthor Commented:
Hi Burniep,
With this solution I will disable all the RFV from the page, where I need to disable only those in the gridview. It also return the following error :

Compiler Error Message: BC30456: 'disableRFV' is not a member of 'ASP.ucontrols_createprod2_ascx'.

Source Error:
Line 421:
Line 422:<br />
Line 423:<asp:CheckBox ID="ckb" runat="server" OnCheckedChanged="disableRFV();" />
Line 424:<br />
Line 425:
 
Should I use an HTML checkbox instead?
0
 
BurniePCommented:
You can still use asp:checkbox, but do it on the onclick.

<asp:CheckBox ID="ckb" runat="server" onclick="disableRFV();" />

0
 
BurniePCommented:
Ok, to disable only gridview validators, change your disable function for this :


function disable() {
        for (var i = 0; i < Page_Validators.length; i++) {
          if (Page_Validators[i].id.indexOf('PackInnGrid') >= 0) {
            ValidatorEnable(Page_Validators[i], false);
          }
        }
      }

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now