Clear session after redirect
-
hi guys. i want to store value in session to keep it between postbacks. after page is changed i don't need value anymore. is there a way to kill session on current page i am, before redirect (changing url)? i dont want to use ViewState.
void Page_Load()
{
if(!Page.IsPostBack)
{
Session["something"] = true
}
}
void Page_LoadComplete()
{
//i need this value between postbacks, but dont want to init it every time
bool something = Session["something"] as bool;
}
/*
i would like to have something like this
void Page_IsChangedOrRedirected()
{
Session["something"] = null;
}
*/ -
hi guys. i want to store value in session to keep it between postbacks. after page is changed i don't need value anymore. is there a way to kill session on current page i am, before redirect (changing url)? i dont want to use ViewState.
void Page_Load()
{
if(!Page.IsPostBack)
{
Session["something"] = true
}
}
void Page_LoadComplete()
{
//i need this value between postbacks, but dont want to init it every time
bool something = Session["something"] as bool;
}
/*
i would like to have something like this
void Page_IsChangedOrRedirected()
{
Session["something"] = null;
}
*/You can use
Session.Remove("something");
wherever you want.
Cheers!! Brij Visit my Blog: http://brijbhushan.net
Check my latest Article :Client Templating with jQuery -
hi guys. i want to store value in session to keep it between postbacks. after page is changed i don't need value anymore. is there a way to kill session on current page i am, before redirect (changing url)? i dont want to use ViewState.
void Page_Load()
{
if(!Page.IsPostBack)
{
Session["something"] = true
}
}
void Page_LoadComplete()
{
//i need this value between postbacks, but dont want to init it every time
bool something = Session["something"] as bool;
}
/*
i would like to have something like this
void Page_IsChangedOrRedirected()
{
Session["something"] = null;
}
*/Am I understanding you correctly, that you need the value to be part of the session as long as the user is using PostBack, but on a new page load, the session value should be empty? If that is the case, then you can do this simply like this
void Page_Load()
{
if(!Page.IsPostBack)
{
Session["something"] = true;
}
else
{
Session["something"] = false;
}
}I wasn't, now I am, then I won't be anymore.