Radiobutton list auto postback
Ok, this is painful for me because yes, I've been coding ASP.NET after classic ASP days. I've so lost the ways of regular HTML controls.
So, here's my scenario.
1) I have a list of radiobuttons on the page, regular old HTML buttons:
<div id="selectOptions">
<form action="Checkout.aspx" method="post" target="_self">
<ul>
<li><label><input type="radio" name="rbRewardsSelectionGroup" id="rbtNoRewardOption" checked="checked" value="0" />None</label></li>
<li><label><inpu开发者_运维知识库t type="radio" name="rbRewardsSelectionGroup" value='1' />Free Shipping</label></li>
<li><label><input type="radio" name="rbRewardsSelectionGroup" value='2' />$100 Store Credit</label></li>
<li><label><input type="radio" name="rbRewardsSelectionGroup" value='3' />$250 Store Credit</label></li>
<li><label><input type="radio" name="rbRewardsSelectionGroup" value='4' />$500 Stored Credit</label></li>
</ul>
</form>
</div>
2) I need to add some javascript to force a postback if any one of these radiobuttons are selected, even the default selected radio button
3) I attempted to add a form and wrap it around the code. I don't know if this will work because I think ASP.NET won't let you have more than one form on a page...or maybe that's just how it is for everyone?
4) Lets say it will work. Ok so I click the radio button. I send a request to Checkout.aspx and then in the code-behind I can grab that data and do a Request["rbRewardsSelectionGroup"] to get reference to that radiobutton group and then perform my server-side value checks...whatever I need to do.
I guess my question is am I going about this right with the way I have this setup currently? I believe I've got the overall concept here outside of using ASP.NET based controls that do all this magic for you.
I don't want to get into why I'm not using an ASP.NET control for this particular piece of code.
2) With jquery, listen for the change event on the radio buttons and submit its parent form:
$("input[@name='rbRewardsSelectionGroup']").change(function(){
$(this).parents('form').submit();
});
3) You can only have one form with a runat="server" property in asp.net
4) Yes, use Request.Form["rbRewardsSelectiongroup"] to get the value of the selection.
精彩评论