I was using This SO answer as a reference for sending a javascript variable to my server side. However when I implement that solution everything comes up correctly in the js alert(), but the Value of my hidden field when I hit the server is always empty.
Javascript and Html:
<script>
function rblSelectionChange()
{
var selection = $('#inAction input:checked').val();
var stuff = $('#<%= clientSelection.ClientID %>').val(selection);
alert(stuff.val());
}
</script>
<asp:HiddenField ID="clientSelection" runat="server" />
<div class="row-fluid">
<asp:RadioButtonList runat="server" ID="inAction" ClientIDMode="Static">
<asp:ListItem onClick="rblSelectionChange();" Value="RuEp" Text="I remember my <b>username</b>. Please email me a new <b>password</b>." />
<asp:ListItem onClick="rblSelectionChange();" Value="ReEu" Text="I remember my <b>email</b>. Please email me my <b>username</b>." />
<asp:ListItem onClick="rblSelectionChange();" Value="ReEup" Text="I remember my <b>email</b>. Please email me my <b>username</b> and a new <b>password</b>." />
</asp:RadioButtonList>
</div>
On the submit event of the page I try to grab the value and it is empty:
protected void btnActionSelect_Click(object sender, EventArgs e)
{
string selection = clientSelection.Value;
...snip...
}
Any idea what I am missing?
UPDATE:
I have tried to change my hidden field to a pure html one, not the asp: control.
<input type="hidden" id="clientSelection" name="clientSelection" value="" />
I have modified the code-behind as follows:
private string _selection = "";
protected void Page_Load(object sender, EventArgs e)
{
//_selection = clientSelection.Value.ToString();
if (IsPostBack)
_selection = Request.Form["clientSelection"];
}
I am still getting nothing for the value Request.Form["clientSelection"]. Important note however is it works in Chrome, FF, and IE10. The browser I am trying to get it to work in is IE 7 8 and 9. If anyone can help me out on this one, it would be greatly appreciated. I am fully stumped.
EDIT: Per request, here is the source of the page when I inspect it in IE10 (with browser and document mode set to IE7)
<DIV id=ctl00_cphBodyWithForm_htmActionSelect class=row-fluid>
<P class=lead>Can't access your account? Please select from the following options: </P>
<SCRIPT>
function rblSelectionChange()
{
var selection = $('#inAction input:checked').val();
var stuff = $('#ctl00_cphBodyWithForm_clientSelection').val(selection);
alert(stuff.val());
}
</SCRIPT>
<INPUT id=ctl00_cphBodyWithForm_clientSelection type=hidden name=ctl00$cphBodyWithForm$clientSelection jQuery191034119593101524303="7">
<DIV class=row-fluid>
<TABLE id=inAction border=0>
<TBODY>
<TR>
<TD><INPUT onclick=rblSelectionChange(); id=inAction_0 type=radio value=RuEp name=ctl00$cphBodyWithForm$inAction jQuery191034119593101524303="8"><LABEL for=inAction_0>I remember my <B>username</B>. Please email me a new <B>password</B>.</LABEL></TD>
</TR>
...snip...
</TBODY>
</TABLE>
</DIV>
<DIV class=span12>
<A class="submitButton roundedBR" href="javascript:__doPostBack('ctl00$cphBodyWithForm$ctl00','')">Continue > </A>
</DIV>
</DIV>
inAction.SelectedValue
in code-behind file? – Satpal Sep 27 '13 at 16:39UniqueID
instead ofClientID
. – James Johnson Sep 27 '13 at 19:21