Dropdown list and browser back button issue

I am working on an ASP.NET VB Web project.  I have a page with a dropdownlist with items (let's say A, B and C).  B is assigned as default selected item.  when a user selects a different item (let's say C) on the dropdownlist it triggers the selectedindexonchange event and do a postback. It all works very well but then when a user clicks on the BACK button of the browser the item the user previsouly selected is highlighted (which is C) but if I look at the code behind using View source from the browser "B" is still marked as SELECTED.  The problem is, if I select B now the selectedindexonchange event won't fire.... how can I solve this problem?  I tried not to cache the page but it still not solve the "SELECTED" issue....
Please help.. very urgent...
Who is Participating?
The issue is when you click "back" button, it will display the cache version of the page. That's why B is shown "selected" in the source code and that causes the selectedindexonchange event won't fire when you select "B" in the drop list (even the dropdownlist highlighted "C").

try add this to your page_load,
        Response.CacheControl = "no-cache"
and now when user clicks "C" and then click "back" button, it will show "B" as highlighted instead of "C".
Seems to me, its browser cache problem
Add the following two lines to your .aspx page and see the difference.

            <meta http-equiv="Expires" content="-1">
            <meta http-equiv="Pragma" content="no-cache">

waimanAuthor Commented:
Thanks for the advices... but things still not quite right....
I put the meta tags and the response.cachecontrol in the code......and that's what happening...
If the default selected item is B (out of A, B, C) in the dropdown list, then when I click on 'C', it kicks off a postback.  Then when I click on the BACK button of the browser, 'B' is highlighted again.  I could still click on A or C and it still works.... occassionally I get the "Warning: Page has expired" from IE in some pages which I am NOT happy with....

However, the ideal situation will be: default item is 'B', when I click on 'C', it kicks off a postback, when I click on the BACK button on the browser, 'C' should be highlighted, and I can click on 'B' again and do another postback.  

The problem I described in my previous posting was: 'B' is always marked as 'SELECTED' behind the scene even 'C' is appeared to be highlighted in the browser, and the postback will not happen (or did weired things) when I click on 'B' again.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

The back button is really difficult to handle.  Have you tried turning smartnavigation on?  It sometimes interferes with javascript, but you can give it a try.
Use ONLY Response.CacheControl = "no-cache" and page won't get expired.

The flow is:
1st - B is selected by default > if user selects "C", page will post back
2nd - Now "C" is highlighted > click "button" and naturally it will go back to previous page which is (1st)

If user clicks "back" button and select "B" and you want page to post back, they can directly select "B" in 2nd stage.
waimanAuthor Commented:
I ended up have to rewrite the onchange event using attributes.add.  The viewstate was absolutely screwed but I did not have time to investigate what really went wrong.  It fired the onselectedindexchange on the first time in debug mode and it did not happen the second time.... no idea... anyway the problem was bypassed ......
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.