Saturday, July 28

How to call a session variable in JQuery?

Assign your session value in your page's Page_Load event-
       protected void Page_Load(object sender, EventArgs e)
    Session["EmployeeID"] = 2;

Then write these following jquery method-  
       function getSessionValue() { 
            var EmployeeID = '<%# Session["EmployeeID"] %>';
            return EmployeeID;
This will work fine if at least a single postback has happend in your page. But, if you want to access your session value while no postback has occurred then you have to assign value to your session variable in your Page's  Page_PreInit Event.
      protected void Page_Init(object sender, EventArgs e)
         Session["EmployeeID"] = 2;
Now,it will work fine also no postback has been done.

     Shibashish Mohanty

No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

shibashish mohanty