Reputation: 344
Currently using 3 radio buttons and grouped them using GroupName.
Radio Button's code
<asp:Panel class="RBPnl" runat="server" ID="pnl_rb">
<asp:RadioButton ID="rb" runat="server" GroupName="rbg_RB" Text="Radio Button" CssClass="RB" />
<label class="RBDesc">Radio Button Descriptions</label>
</asp:Panel>
Now based on certain condition I want to disable a radio button from code behind. Searched SO & Google and most solution mentioned two methods below :
Result :
<span class="aspNetDisabled RB">
<input id="cph_content_rb" type="radio" name="ctl00$cph_content$rbg_rb" value="rb">
<label for="cph_content_rb">Radio Button</label></span>
Result:
<span class="RB" disabled="disabled">
<input id="cph_content_rb" type="radio" name="ctl00$cph_content$rbg_rb" value="rb">
<label for="cph_content_rb">Radio Button</label></span>
As you can see I tried both but still able to check the supposedly disabled radio button because it should disable the input but the code disable at span instead.
I know javascript can solve this by adding disabled attributes to the children (input) of radiobutton but I want to know the method to disable at server side (c#)
Upvotes: 0
Views: 1142
Reputation: 29
I guess your problem is: Asp.net WebForm backend code does not change your html dynamically.
You may compare WebForm with WinForm to see the difference:
So you must be clear about the execution order of each step happened after the webpage sends back something and before it gets rendered in the browser:
So you must make sure your code which disables the radio button is executed in Step 3, and you must know what action on the webpage will trigger Step 1.
Upvotes: 0