Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody !

I work on asp.net webform app and I would to disable an asp:RequierFieldValidator on radio button list.

My radio button list :

XML
<asp:RadioButtonList runat="server" ID="rbtnO360Sync" RepeatDirection="Horizontal" AutoPostBack="true" OnSelectedIndexChanged="RbtnO360Sync_SelectedIndexChanged" 
                        EnableTheming="True" EnableViewState="true">
                        <asp:ListItem Selected="True" Text="Oui" Value="True" />
                        <asp:ListItem Text="Non" Value="False" />
                    </asp:RadioButtonList>


The event RbtnO360Sync_SelectedIndexChanged :

C#
private void UpdateO365SyncSelected()
        {            
            if (SyncO365 && AD)
            {
                rfvIdentifiantMDM.Enabled = true;
                rfvIdentifiantMDM.Visible = true;
                rfvIdentifiantMDM.ControlToValidate = txtIdentifiantMDM.ID;
                rfvIdentifiantMDM.ValidationGroup = "Form";
            }
            else
            {
                rfvIdentifiantMDM.Visible = false;
                rfvIdentifiantMDM.Enabled = false;
                rfvIdentifiantMDM.ValidationGroup = null;
                rfvIdentifiantMDM.ControlToValidate = null;
        }

        protected void RbtnO360Sync_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateO365SyncSelected();
        }


My Required Field Validator and the associated field:

XML
<asp:TextBox runat="server" ID="txtIdentifiantMDM" Visible="true" ReadOnly="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvIdentifiantMDM" ViewStateMode="Disabled" runat="server" Display="dynamic" Text="* Obligatoire pour les comptes Office 365"  SetFocusOnError="true" />


By default the required field validator is activated.

when I click on radio button item "Non" the requied field validator is allways activate

My Question How to desactivate it on click to "Non" radio button item ?

Thanks for you reply !

What I have tried:

I tried to

C#
rfvIdentifiantMDM.Visible = false;
rfvIdentifiantMDM.Enabled = false;
rfvIdentifiantMDM.ValidationGroup = null;
rfvIdentifiantMDM.ControlToValidate = null;


but nothing works
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900