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; } } }
radioButton1.Checked = radioButton2.Checked = radioButton3.Checked = false;- Leonid Malyshev