Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one page which is of data entery and the same page i m binding it all the controls and making the same page as modify page.

i should clear the session when the page is navigating to other page.
But in which page event i should it i dont know.
Posted
Comments
Member 10641779 27-Mar-14 7:36am    
you can try to use when loading new page.
Kornfeld Eliyahu Peter 27-Mar-14 8:11am    
It sound very strange! Can you explain why you want to do such a thing?
Raul Iloc 27-Mar-14 13:45pm    
Did you try my solution (Solution 4) ?

You should do it in Page_Load event but only only if the page was not post back like in the next example:

C#
protected void Page_Load(object sender, EventArgs e)
{
 if (!Page.IsPostBack)
 {
    //clear your params from sesssion here!
    Session["param1"]= null;
    Session["param2"]= null;
    //...

 }
 //.... 
}
 
Share this answer
 
See the requirement.
If you want to clear a particular Session data
Then do as follows
Session["UserData"]=null;
And If you want clear Session data from whole of the application the do as above
Session.Abandon();
 
Share this answer
 
Comments
Christian Amado 27-Mar-14 21:07pm    
This is the best solution that I can see in this thread. Who's downvoted. +5 from me. Excellent answer.
[no name] 27-Mar-14 22:03pm    
Thank you very much such a nice comment.
Raul Iloc 28-Mar-14 1:57am    
The question wasn't about how to clear from session, but about the choosing the right ASP.NET event where the session data to be cleared.
[no name] 28-Mar-14 2:13am    
So Then you have to follow up
Global.asax file with the Session_OnStart and Session_OnEnd events defined.
See for more details
on this link
http://msdn.microsoft.com/en-us/library/ms178583.aspx
For a particular session null no need to mention page_load event. It can be done as well as at any event of a page.
You can Use Session.Clear(); or Session.Abandon();
 
Share this answer
 
In this case you have to save last visited page url on the session.

HttpApplication.BeginRequest Event fires whenever user request page. Even this is the first event which fires once user request the page.

Inside this event you can check if the last page is your page and current page is not equal to last page, you can clear session.

C#
Session["Session_name"]=null;


Thanks
 
Share this answer
 

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