how to end and restore session in asp.net c# -
is possible clear values of session on 1 page , restore session on page in asp.net c#? how? clearing session on page1.aspx redirecting page2.aspx , there session should restored. have tried far:
session.abandon()
not working
code on first page. session["searchtext]
creating problem.
else if (radtabstrip1.selectedindex == 1) { if (!permissions.checkpermissions(session["employeeloggedin"].tostring(), "acctmodf")) { scriptmanager.registerstartupscript(this, page.gettype(), "onload", "alert('you must have accounts: modify permission batch invoice!')", true); } else { // added shiv on 07/14/2015 session["searchtext"] = null; fillbatchinvoicegrid();
code of second page
if (e.commandname == "alpha" || e.commandname == "nofilter") { string value = null; switch (e.commandname) { case ("alpha"): { value = string.format("{0}", e.commandargument); break; } case ("nofilter"): { value = "%"; session["searchduplicate"] = null; session["searchcussalesrep"] = null; break; } } // session["searchletter"] = value; session["searchtype"] = "1"; session["searchtext"] = value; session["searchfilter"] = "1";
i making session[searchtext] = null;
on first page thats why on second page, cant access it.
update:
as per op requirement, session[searchtext] should not same when return first page. hence i'm writing below solution resolve issue.
first page:
session["searchtext"] = "something";
second page:
session["searchedtext"] = session["searchtext"]; session["searchtext"] = "";
old answer:
simple in part, before accessing, check whether null or not.
if(session["searchtext"]!=null) { //do stuffs }
Comments
Post a Comment