7

I want to change the text of a radio button (HTML element), not an ASP.NET component.

How can I change it from ASP.NET?

3 Answers 3

15

Add a simple:

runat="server"

to your HTML tag and it will allow a few of the properties to be modified through code behind.

These are known as "hybrid controls."

9

You would need to add a runat="server" attribute to the HTML for that element.

<input type="radio" id="someRadioId" value="bleh" runat="server">

This will allow you to access the element via its ID, someRadioId. This element in your code behind will be of type HtmlInputRadioButton.

See this article on MSDN

1

A simple RadioButtonList, when initialized like this:

list.Items.Add(new ListItem("item 1", "1"));
list.Items.Add(new ListItem("item 2", "2"));
list.Items.Add(new ListItem("item 3", "3"));

renders to the following HTML:

<table id="list" border="0">
    <tr>
        <td><input id="list_0" type="radio" name="list" value="1" /><label for="list_0">item 1</label></td>
    </tr><tr>
        <td><input id="list_1" type="radio" name="list" value="2" /><label for="list_1">item 2</label></td>
    </tr><tr>
        <td><input id="list_2" type="radio" name="list" value="3" /><label for="list_2">item 3</label></td>
    </tr>
</table>

So via JavaScript you can loop through the elements with the type "radio", grab their id and then look for label elements that have the id as the 'for' value. And update their innerHTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.