pascalmartin
asked on
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="disableR FV();" />
<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:RequiredFieldValidato r ID="reqInnPCB" runat="server" ControlToValidate="txbProd InnP" ValidationGroup="MyVal"
ErrorMessage="*" Display="Dynamic" EnableViewState="true" />
<asp:RegularExpressionVali dator id="ValInnPcb" runat="server" Display="Dynamic"
ControlToValidate="txbProd InnP" ValidationExpression="^[1- 9]+[0-9]*$ " ErrorMessage="Integer only!"></asp:RegularExpres sionValida tor>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Length">
<ItemStyle width="60px" />
<ItemTemplate><asp:TextBox ID="txbProdInnL" runat="server" CssClass="rowEdit" Width="60px" />
<asp:RequiredFieldValidato r ID="reqInnLength" runat="server" ControlToValidate="txbProd InnL" ValidationGroup="MyVal"
ErrorMessage="*" Display="Dynamic" EnableViewState="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
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="disableR
<asp:GridView ID="PackInnGrid" runat="server" CssClass="grid" Width="620px" AutoGenerateColumns="False
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
<asp:RequiredFieldValidato
ErrorMessage="*" Display="Dynamic" EnableViewState="true" />
<asp:RegularExpressionVali
ControlToValidate="txbProd
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Length">
<ItemStyle width="60px" />
<ItemTemplate><asp:TextBox
<asp:RequiredFieldValidato
ErrorMessage="*" Display="Dynamic" EnableViewState="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This should work :
<script language="JavaScript" type="text/javascript">
function disableRFV()
{
Page_ValidationActive = false;
}
<script language="JavaScript" type="text/javascript">
function disableRFV()
{
Page_ValidationActive = false;
}
You can use ValidatorEnable function, like below:
ValidatorEnable(RequiredFi eldValidat or1, false);
and then call ValidatorValidate(), because the validator is disabled in above line, so it will always pass the validation test.
ValidatorValidate(Required FieldValid ator1);
ValidatorEnable(RequiredFi
and then call ValidatorValidate(), because the validator is disabled in above line, so it will always pass the validation test.
ValidatorValidate(Required
Is your problem resolved? Let me know your comments
ASKER
meispisces: I have seen the forum but it does not respond to what I need.
ASKER
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="disableR FV();" />
Line 424:<br />
Line 425:
Should I use an HTML checkbox instead?
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
Source Error:
Line 421:
Line 422:<br />
Line 423:<asp:CheckBox ID="ckb" runat="server" OnCheckedChanged="disableR
Line 424:<br />
Line 425:
Should I use an HTML checkbox instead?
You can still use asp:checkbox, but do it on the onclick.
<asp:CheckBox ID="ckb" runat="server" onclick="disableRFV();" />
<asp:CheckBox ID="ckb" runat="server" onclick="disableRFV();" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://forums.asp.net/p/839953/840084.aspx
http://www.velocityreviews.com/forums/t109917-disable-requiredfieldvalidator-with-javascript.html
http://www.velocityreviews.com/forums/t84388-disabling-required-field-validator.html
hope this helps