Solved

Disable RequiredFieldValidator in a gridview

Posted on 2010-11-28
8
1,480 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Expert Comment

by:meispisces
Comment Utility
0
 
LVL 16

Expert Comment

by:BurnieP
Comment Utility
This should work :

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


0
 
LVL 13

Expert Comment

by:devlab2012
Comment Utility
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
 
LVL 7

Expert Comment

by:meispisces
Comment Utility
Is your problem resolved? Let me know your comments
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Author Comment

by:pascalmartin
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now