Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI ,

I have a list<t> on server side in C#.I am keeping this list in a session.I needto clear this session values on client side using javascript.anyone know the solution pls let me know.
Posted

Session values are never accessible at client side. It entirely resides on server memory. Its not possible to destroy session from client side.

However u can use ajax call to server side to clear session, without full page postback. :)
 
Share this answer
 
Session is a server side technology and JavaScript is client side. So JavaScript code knows nothing about the Session. If you need to clear some session value, you will need to post the form to server and tell it to clear that value. The good thing is you can post the form using JavaScript.
You would like to read about -
jQuery.ajax()
[^] to implement this. :thumbsup:
 
Share this answer
 
v2
If you want to clear out the entire session use Session.Clear().
If you want to abandon a session destroying the session , use <codelang>Session.Abandaon().

If you just want to clear the list, you can access the session and use something like <code>session[myList] = null;
 
Share this answer
 
v2
Comments
Ankur\m/ 4-Apr-13 5:53am    
That wasn't the question at all.
Abhinav S 4-Apr-13 6:27am    
Ok I missed OP wanted to clear through JavaScript.
Well - in any case, OP can make a call to the server and then clear the list.
Ankur\m/ 4-Apr-13 6:33am    
"Well - in any case, OP can make a call to the server and then clear the list."
Seems that's what OP doesn't know. Not my vote btw.
Sample Example Here.....That can Help you...

XML
<%@ Page language="c#" AutoEventWireup="true" %>
<script runat="server">
void Page_Load()
{
Session["MySessionVar"]="Hello world";
}
</script>
<html>
<script language="JavaScript">
var mySessionVar="<%= Session["MySessionVar"] %>";
</script>
<body>
<form runat="server"></form>
</body>
</html>
 
Share this answer
 
Comments
Ankur\m/ 4-Apr-13 5:53am    
How would this clear the session on the client side?
vmsrdy 19-Apr-13 7:40am    
Sorry for replying late. but when I am getting Object not defined error message.Actually I am using in side the user control and also I have master page.IS this a problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900