When an Input Button is clicked In the aspx it calls a JavaScript that sets up Sessions Variables and calls WebMethod.
The Input Box txtUserID has a value but Session["UserID"] is always null in WebMethod.
Why and how do I fix it?
html:
<div>
<label for="txtUserID">USER ID:</label>
<input type="text" id="txtUserID" name="txtUserID" runat="server" style="width:150px;"/>
</div>
Script:
function SetSessionVariables()
{
//var CurrentDate2 = document.getElementById("txtUserID").value;
'<%Session["UserID"] = txtUserID.Value; %>';
}
Code Behind (Web Method):
[System.Web.Services.WebMethod(EnableSession = true)]
public static void SaveData()
{
string sUserID= HttpContext.Current.Session["UserID"].ToString();
}