[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dropdown list and browser back button issue

Posted on 2006-04-06
6
Medium Priority
?
536 Views
Last Modified: 2008-08-04
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...
Wai
0
Comment
Question by:waiman
6 Comments
 
LVL 12

Accepted Solution

by:
bsdotnet earned 600 total points
ID: 16389944
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".
0
 
LVL 7

Assisted Solution

by:irps20001
irps20001 earned 450 total points
ID: 16389967
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">


HTH
Rana
0
 

Author Comment

by:waiman
ID: 16396938
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Assisted Solution

by:gtmljsc
gtmljsc earned 450 total points
ID: 16397256
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.
0
 
LVL 12

Assisted Solution

by:bsdotnet
bsdotnet earned 600 total points
ID: 16398447
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.
0
 

Author Comment

by:waiman
ID: 16423248
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 ......
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question