There are three radiobuttons, you need to turn off the button if none of them is selected.

radioButton1.Checked = radioButton2.Checked = radioButton3.Checked = false; if (radioButton1.Checked == true || radioButton2.Checked == true || radioButton1.Checked == true) { button1.Enabled = true; } else { button1.Enabled = false; } 

It seems to work, but does not work. Locks the button tightly.

  • You do not confuse? The meaning of radio beats is just that one of them is always chosen. - Kromster
  • And why should it work differently if you reset all 3 to false radioButton1.Checked = radioButton2.Checked = radioButton3.Checked = false; - Leonid Malyshev
  • it's just a reset line, the code should activate a button when the value changes to true, that is, the button is activated by the user, this does not happen - kios
  • here everything is initially wrong. if this code is in the event handler of the radiobutton mark event, then it will never work as it should. You first mark all radiobats as NOT marked, and then among them look for what is marked. See my answer, even though it is on WPF, but it's simple and straightforward - Yurii Manziuk

2 answers 2

Make sure that there is one handler for all radiobuttons with their check code example:

 private void radioButton1_Checked(object sender, RoutedEventArgs e) { button.IsEnabled = true; } 

Window code:

 <DockPanel LastChildFill="True"> <Button x:Name="button" DockPanel.Dock="Bottom" Content="Кнопка" HorizontalAlignment="Center" Height="28" Width="381" Margin="15" IsEnabled="False"/> <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center"> <RadioButton Name="radioButton1" Margin="5" GroupName="RB" Checked="radioButton1_Checked">RadioButton 1</RadioButton> <RadioButton Name="radioButton2" Margin="5" GroupName="RB" Checked="radioButton1_Checked">RadioButton 2</RadioButton> <RadioButton Name="radioButton3" Margin="5" GroupName="RB" Checked="radioButton1_Checked">RadioButton 3</RadioButton> </StackPanel> </DockPanel> 

Then, by ticking any RadioButton, the button will become active.

  • hash tag si sharpe, problem solved, thanks everyone. - kios

If it is not important to manage the state of the button on the server side, then you can get by with javascript.

HTML

 <head> <title>Test Radio Buttons</title> <script type="text/jscript"> function EnableSubmit() { var btn = document.getElementById("button1"); btn.disabled = false; } </script> </head> <body> <div class="title radiobar"> <h3>Radio buttons:</h3> <label> <input type="radio" name="testRadio" id="radioButton1" onclick="EnableSubmit()" /> radioButton1 </label> <label> <input type="radio" name="testRadio" id="radioButton2" onclick="EnableSubmit()" /> radioButton2 </label> <label> <input type="radio" name="testRadio" id="radioButton3" onclick="EnableSubmit()" /> radioButton3 </label> </div> <p> <button id="button1" disabled="disabled">OK</button> </p> </body> 

If you want to control a button on the server side, then after changing the state of each radio button you need to AutoPostBack page to the user (the AutoPostBack properties AutoPostBack set to true ). Without this, he will not see any changes on the server, because he sees the compiled page in the browser.

.Aspx file:

 <body> <form id="form1" runat="server"> <div class="title radiobar"> <h3>Radio buttons:</h3> <label> <asp:RadioButton runat="server" GroupName="testRadio" ID="radioButton1" AutoPostBack="true" /> radioButton1 </label> <label> <asp:RadioButton runat="server" GroupName="testRadio" ID="radioButton2" AutoPostBack="true" /> radioButton2 </label> <label> <asp:RadioButton runat="server" GroupName="testRadio" ID="radioButton3" AutoPostBack="true" /> radioButton3 </label> </div> <p> <asp:Button ID="button1" runat="server" Text="Submit" Enabled="false" /> </p> </form> </body> 

.Aspx.cs file:

 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) // если это первая загрузка страницы { radioButton1.Checked = radioButton2.Checked = radioButton3.Checked = false; } else // если повторная загрузка после отправки на сервер по нажатию на радиобаттон { if (radioButton1.Checked == true || radioButton2.Checked == true || radioButton3.Checked == true) { button1.Enabled = true; } } } 
  • this is not javascript and not html, but C #) or correct the answer or delete - Yurii Manziuk
  • Has added. Nowhere has it been said that it is necessary to manage the state on the server side. - Ponio
  • Nowhere is it said that this is ASP.NET - Yurii Manziuk
  • That is, we are trying in vain to help the author, who did not really explain anything. - Ponio
  • not so many options. WPF, ASP, WinForm. and all that is needed is already in the answers, not at least - you can figure it out - Yurii Manziuk