Checking Selected Radio Button after POST
Posted
by coffeeaddict
on Stack Overflow
See other posts from Stack Overflow
or by coffeeaddict
Published on 2010-06-09T03:36:00Z
Indexed on
2010/06/09
3:42 UTC
Read the original article
Hit count: 169
html
I've been using ASP.NET controls which perform a lot of the manual for you.
But I'm going back to the basics, what everyone else does. I'm using standard input tags. So for example if I have a radio button group and I select a button. When the form submits and does a POST back to whatever action="MyPage.aspx" then to grab and check the radio button's value that was selected is it always done like this below?
<label><input type="radio" name="rbGroup" value='<%# ((Action)Container.DataItem).ID %>'/><%# ((Action)Container.DataItem).Name %></label>
So here I'm appending the ID to the value. And then when it hits the page that my action specifies, I'm checking to see which was selected by trimming off and getting that ID from the value:
string selection = Request.Form["rbGroup"];
string dbRecordIdSelected = int.Parse(selection.Substring(1));
so now I can check the id they selected...that is the ID of the db record that gave that selected radio it's name.
Is that how you basically always check what radio was selected by checking the name/value pair that comes across for that selected radioButton group name? And then you can append stuff like IDs or whatever you want to grab and parse out to then do additional logic on the server-side once that header reaches the server and your specified page in the action attribute?
The above code is not production code, just something to explain what I'm talking about.
© Stack Overflow or respective owner