clearing previous selection on browser's back button click

R

Rosanne

Is there a way to clear the SelectedIndex of a listbox when th
browser's back button is clicked?

I have a page that contains a server side list box with AutoPostBack
True. When the user clicks an item in the listbox, they are redirecte
to an information page based on their selection. On this informatio
page, if the user clicks the browser's back button they are taken bac
to the first page with the item in the listbox still highlighted.
Therefore, if they click anything else on that page that causes a pos
back, the SelectedIndexChanged event of the listbox is firing agai
taking them back to the information page. Is there anyway to clear th
SelectedIndex of this listbox when the browser's back button is clicked


Thanks in advance!!!

Rosann
 
S

S. Justin Gengo

Rosanne,

How about adding a javascript to the page. If you add it with
Page.RegisterStartupScript the script will run every first page load. Use
the script to reset the SelectedIndex.

Something like this:

Page.RegisterStartupScript("SelectReset", "<script
language=""javascript"">document.getElementById('MySelectBox').selectedIndex
= 0;</script>")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
V

Vonnie

Using this in the Page Load event should work

Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetAllowResponseInBrowserHistory(False)
 
R

Rosanne

Hi Vonnie -

Thanks for the suggestion above! I added the 2 lines of code you gav
me. Now when they click the browser's back button, the page is expire
and they have to click refresh. Makes sense. And when they clic
refresh, the item in the list box is no longer selected so it's al
working correctly. However, I didn't want the page to expire - I onl
wanted the selection to be cleared. Is there anyway to do that? Th
users want to be able to use the back button - they will complain abou
the page expiring and having to refresh. Just wondering if there's
work around.

Thanks again for the suggestion! And thanks in advance for an
thoughts on this issue.

Rosann
 
Joined
Aug 20, 2007
Messages
1
Reaction score
0
jain

did u get any solution for ur problem .If so plz post it. I do need the same.:sad:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top