Reputation: 77
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
Reputation: 131
You could say Session["filter"]=string.Empty
on 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
Reputation: 1198
You could use ViewState["filter"] instead which would be specific to that page.
Upvotes: 2