How do I write the code to get a group of radio buttons with the same name to maintain their state?
Good question. It's really no more difficult then getting a single radio button to maintain its state,
it just takes more code. Take a look at the following block of code.
Multiple Radio Buttons With The Same Name That Maintain Their State:
<input type="radio" name="multiple_state" value="1"
<% If Request.QueryString("multiple_state") = "1" Then Response.Write "checked=""checked""" %>
/>
<input type="radio" name="multiple_state" value="2"
<% If Request.QueryString("multiple_state") = "2" Then Response.Write "checked=""checked""" %>
/>
<input type="radio" name="multiple_state" value="3"
<% If Request.QueryString("multiple_state") = "3" Then Response.Write "checked=""checked""" %>
/>
The code above checks the value of the
radio button parameter that was passed to the page once for each radio button in the group. When the value
of the parameter matches the value of the radio button that we're currently checking for, it sets the
"checked" parameter of that radio button so that button is the one selected when
the page is rendered. It's really quite simple, but it's a shame it's such a tedious task.
Not having to manage state in this manner is one of the great benefits of moving to
ASP.NET web controls since they handle all the state managment for you.
Please note: This form is only for submitting questions about the sample for us to consider including in the FAQ. If we feel the question merits inclusion, we will include it along with a reply. We will not respond to your email individually.