Change Hidden Field Value With Jquery And Get The New Value In Server
I change value off the hidden field with jquery and now i want to get the new value in server. i use asp.net and this is my jquery code: $('#HiddenField').val('NewValue'); and thi
Solution 1:
I tried with this on my page,
<!DOCTYPE html><html><headrunat="server"><title></title></head><body><formid="form1"runat="server"><div><asp:Buttonrunat="server"ID="goBtn"Text="Go"OnClick="goBtn_Click" /><inputid="HiddenField"type="hidden"runat="server"value="" /><asp:TextBoxrunat="server"ID="testTxt"></asp:TextBox></div></form><scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script><scripttype="text/javascript">
$(document).ready(function () {
$('#<%=HiddenField.ClientID %>').val("Test");
});
</script></body></html>
and this in the code behind,
protectedvoidgoBtn_Click(object sender, EventArgs e)
{
testTxt.Text = HiddenField.Value;
}
when you press the go button, the new value is available on the server.
Solution 2:
You need to use the ClientID of your hidden field in the JQuery selector such as:
$('#<%= HiddenField.ClientID %>').val("NewValue");
Or, alternatively, use a style for the hidden field and access it by the class, such as:
<inputid="HiddenField"type="hidden" runat="server" value="" CssClass="hidden"/>
$('.hidden').val("NewValue");
Post a Comment for "Change Hidden Field Value With Jquery And Get The New Value In Server"