By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

clearing previous selection on browser's back button click

P: n/a

Is there a way to clear the SelectedIndex of a listbox when the
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 redirected
to an information page based on their selection. On this information
page, if the user clicks the browser's back button they are taken back
to the first page with the item in the listbox still highlighted.
Therefore, if they click anything else on that page that causes a post
back, the SelectedIndexChanged event of the listbox is firing again
taking them back to the information page. Is there anyway to clear the
SelectedIndex of this listbox when the browser's back button is clicked?
Thanks in advance!!!

Rosanne
--
Rosanne
------------------------------------------------------------------------
Rosanne's Profile: http://www.highdots.com/forums/m283
View this thread: http://www.highdots.com/forums/t2946552

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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('M ySelectBox').selectedIndex
= 0;</script>")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Rosanne" <Ro************@no-mx.forums.yourdomain.com.au> wrote in message
news:Ro************@no-mx.forums.yourdomain.com.au...

Is there a way to clear the SelectedIndex of a listbox when the
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 redirected
to an information page based on their selection. On this information
page, if the user clicks the browser's back button they are taken back
to the first page with the item in the listbox still highlighted.
Therefore, if they click anything else on that page that causes a post
back, the SelectedIndexChanged event of the listbox is firing again
taking them back to the information page. Is there anyway to clear the
SelectedIndex of this listbox when the browser's back button is clicked?
Thanks in advance!!!

Rosanne
--
Rosanne
------------------------------------------------------------------------
Rosanne's Profile: http://www.highdots.com/forums/m283
View this thread: http://www.highdots.com/forums/t2946552

Nov 19 '05 #2

P: n/a
Using this in the Page Load event should work

Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Fa lse)


"Rosanne" <Ro************@no-mx.forums.yourdomain.com.au> wrote in message
news:Ro************@no-mx.forums.yourdomain.com.au...

Is there a way to clear the SelectedIndex of a listbox when the
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 redirected
to an information page based on their selection. On this information
page, if the user clicks the browser's back button they are taken back
to the first page with the item in the listbox still highlighted.
Therefore, if they click anything else on that page that causes a post
back, the SelectedIndexChanged event of the listbox is firing again
taking them back to the information page. Is there anyway to clear the
SelectedIndex of this listbox when the browser's back button is clicked?
Thanks in advance!!!

Rosanne
--
Rosanne
------------------------------------------------------------------------
Rosanne's Profile: http://www.highdots.com/forums/m283
View this thread: http://www.highdots.com/forums/t2946552

Nov 19 '05 #3

P: n/a

Hi Vonnie -

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

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

Rosanne
--
Rosanne
------------------------------------------------------------------------
Rosanne's Profile: http://www.highdots.com/forums/m283
View this thread: http://www.highdots.com/forums/t2946552

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.