In .NET 4.5...
I am trying to read this hidden field:
<asp:HiddenField ID="test2" runat="server" Value="" Visible="false" ClientIDMode="static"/>
which the value is being set in the code behind here:
public static string TestSessionValue
{
get
{
object value = HttpContext.Current.Session["TestSessionValue"];
return value == null ? "" : (string)value;
}
set
{
HttpContext.Current.Session["TestSessionValue"] = value;
}
}
TestSessionValue = String.Format("EmployeeCredential_ViewList.aspx?" + Employeeid + "={0}&" + StrIsadmin + "={1}", _empCredential.EmployeeId, IsAdmin);
test2.Value = TestSessionValue;
and then I am trying to read the value in javascript like so:
var hv = $('input[id$=test2]').val();
I have also tried this without success:
var hv = $('#test2').val();
How do I successfully read an asp HiddenField value in javascript?