jQuery
$(document).ready(function () {
$('#ButtonRadioValue').click(function () {
var selValue = $('input[name=radio]:checked').val();
});
});
Radio
<div id="radio" align="center">
<input type="radio" id="radio1" value="BtnNextCaseClick" name="radio" checked="checked"/><label for="radio1" style="width: 109px; margin-right:-.9em">Next</label>
<input type="radio" id="radio2" value="CloseCase" name="radio" /><label for="radio2" style="margin-right:-.9em">Close Case</label>
<input type="radio" id="radio3" value="CloseWeb" name="radio" /><label for="radio3" style="width: 109px">Close Web</label>
</div>
So, below that radio I have a button, and I want it to execute different code behind according to radio selection. That value is stored in selValue. So how can I tell onclick event to run what’s inside of selValue
Button
<asp:Button ID="ButtonRadioValue" CssClass="customButton" runat="server" onclick=" js variable here" Text="Aceptar" style="width: 111px; height: 30px"/>
Thanks.
EDIT
Since there was no real need for client-side procedure. I did it from Server side with this.radio1.Checked == true
Update: It appears I have misunderstood what is required, so I will leave my original below
If you want to know which radio button was selected on the post-back, then either make the radio’s server-side controls (either by converting into
<asp:RadioButton>or simply addingrunat="server"to them. Then you can test forradio1.Checked, etc.Otherwise you can check the form data using
Request.Form("radio1"). If result isNothing(VB.Net) ornull(C#) then the radio was not selected. If there is a value there, you know the radio is selected.Original / incorrect assumption
Unless I’ve misunderstood the issue, you don’t need to have a special attribute in the
<asp:Button>as you can do this just in the jQuery you’ve already written.Add the following after your
var selValue...To produce…
One thing to note is that if the control is within Master Page, Placeholder, etc, then the button will need the full ClientID, otherwise the jQuery will not find it
As a side note, the
OnClickattribute of the<asp:Button>is used to wire-up the event handler for the click on a post-back to the server. If you want to run javascript then you want to use theOnClientClickattribute, which will produce anonclickattribute in the rendered HTML