Solved

Disable RequiredFieldValidator in a gridview

Posted on 2010-11-28
8
1,529 Views
Last Modified: 2012-05-10
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
Comment
Question by:pascalmartin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Expert Comment

by:meispisces
ID: 34225371
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34225494
This should work :

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


0
 
LVL 13

Expert Comment

by:devlab2012
ID: 34225574
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:meispisces
ID: 34225625
Is your problem resolved? Let me know your comments
0
 

Author Comment

by:pascalmartin
ID: 34226009
meispisces: I have seen the forum but it does not respond to what I need.
0
 

Author Comment

by:pascalmartin
ID: 34226021
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
 
LVL 16

Expert Comment

by:BurnieP
ID: 34226030
You can still use asp:checkbox, but do it on the onclick.

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

0
 
LVL 16

Accepted Solution

by:
BurnieP earned 500 total points
ID: 34226058
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Checking a checkbox based on SQL DataReader boolean value in ASP.NET(VB) 2 45
asp.net web application 3 44
Need syntax help building hyperlink 2 40
ASP.NET MVC - Views 3 40
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question