<p>I'm trying to disable a bunch of controls with JavaScript (so that they post back values). All the controls work fine except for my radio buttons as they lose their value. In the below code which is called via a recursive function to disable all child controls the Second else (else if (control is <code>RadioButton</code>)) is never hit and the RadioButton control is identified as a <code>Checkbox</code> control.</p>

<pre><code>    private static void DisableControl(WebControl control)
    {

        if (control is CheckBox)
        {
            ((CheckBox)control).InputAttributes.Add("disabled", "disabled");

        }
        else if (control is RadioButton)
        { 

        }
        else if (control is ImageButton)
        {
            ((ImageButton)control).Enabled = false;
        }
        else
        {
            control.Attributes.Add("readonly", "readonly");
        }
    }
</code></pre>

<p>Two Questions:<br>
 1. How do I identify which control is a radiobutton? <br>
 2. How do I disable it so that it posts back its value?</p>

[{'answer_id': 32203, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Off the top of my head, I think you have to check the "type" attribute of the checkbox to determine if it\'s a radio button.</p>\n'}, {'answer_id': 32473, 'author': 'Nicholas', 'author_id': 2808, 'author_profile': 'https://Stackoverflow.com/users/2808', 'pm_score': 3, 'selected': True, 'text': '<p>I found 2 ways to get this to work, the below code correctly distinguishes between the RadioButton and Checkbox controls.</p>\n\n<pre><code>    private static void DisableControl(WebControl control)\n    {\n        Type controlType = control.GetType();\n\n        if (controlType == typeof(CheckBox))\n        {\n            ((CheckBox)control).InputAttributes.Add("disabled", "disabled");\n\n        }\n        else if (controlType == typeof(RadioButton))\n        {\n            ((RadioButton)control).InputAttributes.Add("disabled", "true");\n        }\n        else if (controlType == typeof(ImageButton))\n        {\n            ((ImageButton)control).Enabled = false;\n        }\n        else\n        {\n            control.Attributes.Add("readonly", "readonly");\n        }\n    }\n</code></pre>\n\n<p>And the solution I used is to set SubmitDisabledControls="True" in the form element which is not ideal as it allows a user to fiddle with the values but is fine in my scenario. The second solution is to mimic the Disabled behavior and details can be found here: https://web.archive.org/web/20210608183803/http://aspnet.4guysfromrolla.com/articles/012506-1.aspx\'><a href="https://web.archive.org/web/20210608183803/http://aspnet.4guysfromrolla.com/articles/012506-1.aspx" rel="nofollow noreferrer">https://web.archive.org/web/20210608183803/http://aspnet.4guysfromrolla.com/articles/012506-1.aspx</a>.</p>\n'}]
['https://Stackoverflow.com/questions/32173', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2808/']