Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I store the EmployeeIds in the session variable and click the button which generate the report of the particular Employees depending on the EmployeeIds stored in session variable. But when I go back where I clicked the button and second time click the button without any selecting EmployeeIds report show me all the report previously selected EmployeeIds records. Now where I have to clear the session? Or any other idea to pass the EmployeeIds to another page and clear it's value when go back to previous page or redirect to other page? Please don't suggest me to use QueryString I don't have to use it.
Posted

Use either Session.Abandon or Session.Clear().
 
Share this answer
 
Comments
Nithin Sundar 29-Aug-12 1:23am    
If comments had a thumbsup icon. :D
Abhinav S 29-Aug-12 2:33am    
Voting is always an option. :D
Nithin Sundar 29-Aug-12 2:39am    
That 5 was actually voted long before even the milkyway came into being!
Abhinav S 29-Aug-12 2:56am    
Thank you. :)
Try this:
C#
protected void btnLogout_Click(object sender, EventArgs e)
    {
        //clear session variables
        Session["Name"] = "";
        Session["Address"] = "";
        Session["Phone"] = "";
        //redirect to index page
        Response.Redirect("index.aspx");
    }

Refer: this article[^]
 
Share this answer
 
v2
In page load of first page. if its not postback check whether that session variable exists and delete it.
C#
Session.Remove("varName");

so whenever its going back to previous page, this session variable will be removed.
 
Share this answer
 
v3
Comments
Karwa_Vivek 29-Aug-12 1:29am    
you can't Set Session Variables to Null.
Session["Employee"]=null will return you a "Null constants is no longer supported.
Santhosh Kumar Jayaraman 29-Aug-12 1:39am    
Thanks. Updated the solution
you can try Like this
Place a back Button on the Page Where you Showing the Report based on selection.
On the Click of that button redirect this to a blank page
there you clear your session and redirect back to page
where you selecting the employee ID.

Let If pageSelect is page Containing your Button
on click you going to pageReport
There you Place a back Button,
on click of Back Button Click
Redirect to pageSwitch
here you clear your session
and also Redirect to pageSelect.

May this helps you.
 
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