Below is my Jquery code and I would like to pass Session paramater e.g. Session["ID"]. Jquery calls ASHX page
All below parameters are working fine and the session parameter has a value, but how can I pass session paramater from Jquery?
So below code "paramater Sessionparameter" should be replaced with Session["ID"] or something like that. How can I do that?
please advice?
$('input[name$=btnTab1Save]').click(
function (e) {
// debugger;
// AJAX call to the handler
$.post(
'Consulting.ashx',
// data to the handler in the form of QueryString
{
tab: 'tab1',
// id is the second column within the row
Ilac_id: prevRow.find('td:eq(0)').text(),
ID: SESSION_PARAMATER,
begindate: $('input[name$=begindate]').val(),
weigth: $('input[name$=weigth]').val(),
continue: true,
freq: $('input[name$=freq]').val(),
reason: $('input[name*=radListreason]:checked').val(),
freq2: $('input[name$=radListfreq2]:checked').val(),
freetext: $('input[name$=freetext]').val()
},
// callback function
// data is the JSON object
function (data) {
if (data.Success) {
// close the tab
}
},
"json"
);
});
I can read my parameters like Convert.Toint(context.Request.Form["ID"]));
data.weigth = Convert.ToInt32(context.Request.Form["weigth"]);
I tried : '<%= Session["ID"] .ToString() %>', but it's not working....
If the information is in the session, the ASHX can access directly the session content.
You need to implement IReadOnlySessionState and you will be fine.
<% @ webhandler language="C#" class="MyClass" %>
using System;
using System.Web;
using System.Web.SessionState;
public class MyClass: IHttpHandler, IReadOnlySessionState
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Write(ctx.Session["ID"]);
}
}
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