I am passing a variable to a session via WebMethod
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public static bool lookEventQ(int eventuid)
{
HttpContext.Current.Session["Q_EVENT_ID"] = eventuid;
return true;
}
Calling it by using jQuery:
$.ajax({
url: "<%= ResolveUrl("~/public-conference.aspx")%>/lookEventQ?eventuid=" + event,
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
//DO STUFF
}
});
But then, on another page, try to access to this session variable:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (int.TryParse(Request.Form.Get(CONST_postKey), out eventID))
{
if(eventID == int.Parse(HttpContext.Current.Session["Q_EVENT_ID"])){
//Do other stuff
}
}
}
}
But when tring to access, the Session is empty
Found the solution. As the asp file doesn't contains a ScriptManager with property EnablePageMethods
set to true
, the session not maintains.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With