Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
HI ,
 
I have a list 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 4-Apr-13 0:32am
vmsrdy426
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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. Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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. Thumbs Up | :thumbsup:
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you want to clear out the entire session use Session.Clear().
If you want to abandon a session destroying the session , use Session.Abandaon().
 
If you just want to clear the list, you can access the session and use something like <code>session[myList] = null;
  Permalink  
v2
Comments
Ankur\m/ at 4-Apr-13 5:53am
   
That wasn't the question at all.
Abhinav S at 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/ at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Sample Example Here.....That can Help you...
 
<%@ 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>
  Permalink  
Comments
Ankur\m/ at 4-Apr-13 5:53am
   
How would this clear the session on the client side?
vmsrdy at 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)

  Print Answers RSS
0 OriginalGriff 400
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100