Header add

 In this article we will learn Get HttpContext.Current.Session value in JavaScript or jQuery in ASP.Net.

Session object or Session variable is stored on Server and hence in order to get its value in JavaScript or jQuery, an AJAX call will be done to the Server Side method in ASP.Net using C#.

HTML Markup

The HTML Markup consists of an ASP.Net TextBox and a HTML Button with some bootstrap styling.




Calling the WebMethod using jQuery AJAX

The Set Button has been assigned a jQuery Click event handler.

Inside the Click event handler, an AJAX call is made to the SetSession WebMethod using jQuery AJAX and the value of the UserName TextBox is sent to the WebMethod.

The WebMethod then returns a string which is displayed using JavaScript Alert Message Box.


Server Side Web Method

Inside the SetSession WebMethod, the value sent from the Client Side is received as parameter and is set into the Session variable.

Finally, the value is read back from the Session variable and sent back to the Client along with Current Server’s Date and Time in string format.



Output


</> Find the Source Code in Github

  Summary
In this tutorial we discussed how to Get HttpContext.Current.Session value in JavaScript or jQuery in ASP.Net. If have any question related to this topic then give your feedback.

Post a Comment

Previous Post Next Post