How to clear the session variable in asp.net design source file

Someone asked on Stack Overflow:

Session[“pageIndex”] this is my variable which is used in all aspx.cs pages

I used

$('#btn_click').click(function(){
sessionStorage.removeItem('pageIndex');
)}; 

to clear the session variable in design source file but it doesn’t works

help me thanks in advance

I posted the following answer, which was chosen as the accepted answer:

I recommend you throw the page number into the query string, then in the Page_Load event, you check for it. If its there, you go to that page directly, otherwise you load the first page.

This should support browser back button functionality taking you to the correct page.

The issue you’re experiencing is that ASP.NET is letting you change the page content without changing the url.

Notable comments

Nate (0 upvotes): @SatG_shanu I recommend that you revert the edit to your question here, and post a new question.


Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.

signed letter b

Dad. Geek. Gamer. Software developer. Cloud user. Old Car enthusiast.  Blogger.


Top Posts


profile for Nate on Stack Exchange, a network of free, community-driven Q&A sites
a proud member of the blue team of 512KB club
Thoughts, opinions, and ideas shared here are my own. © 2026 Nate Bross.