Shiv
Shiv

Reputation: 77

How do I remove Session variable value on redirect to another page

I am using a Session["filter"] variable to store the value of a selected dropdown value when a page redirects to itself. But, if any other page is opened then the variable value should be removed. How do I achieve this?

Upvotes: 0

Views: 984

Answers (2)

meetkichu
meetkichu

Reputation: 131

You could say Session["filter"]=string.Emptyon the landing page if the page Redirect page is on the same web site/application.

If it is not then you can clear the session variable using onselectedindexchanged of dropdown event.

In the case of server page inside the application you can also check if page exist like below before clearing a session value

System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists("~/SomePage.aspx"); 

Upvotes: 1

pln
pln

Reputation: 1198

You could use ViewState["filter"] instead which would be specific to that page.

Upvotes: 2

Related Questions