Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

wrong option selected in dropdownlist

59 views
Skip to first unread message

sam

unread,
Mar 7, 2006, 6:47:20 AM3/7/06
to
Hi,
I have a bound dropdownlist with an event handler
OnSelectedIndexChanged.

If I select a value I'm redirected to another page. I come back using
the browser's back button, and the option is still selected. So far so
good. But the very weird thing is that if I look at the source code :

<option selected="selected" value="13808">DataPage6</option>
<option value="13805">DataPage5</option>
<option value="13489">DataPage4</option>

and yet, I've got the second item (DataPage5) selected in the list.
So what's going on there ????

Thanks for helping.
Sam

Munawar Hussain

unread,
Mar 7, 2006, 7:28:22 AM3/7/06
to
Hi,

Would you make it bit clear .. what is actual problem....
What you want?
What is happening?

Thanks..


"sam" <samuelb...@googlemail.com> wrote in message
news:1141732039.9...@i39g2000cwa.googlegroups.com...

sam

unread,
Mar 7, 2006, 7:42:07 AM3/7/06
to
Ok, watch that :

In the load event:

If Not IsPostBack Then
'get data from database and bind dropdownlist
End If

in the selectedindexchanged event handler:

Public Sub OnSelectedIndexChanged(ByVal sender As Object, ByVal e As
EventArgs)
Dim q As New Query(CType(sender,
DropDownList).SelectedItem.Text, CInt(CType(sender,
DropDownList).SelectedItem.Value))
Session("CurrentQuery") = q
Response.Redirect("Flow.aspx")
End Sub

Then when I browse back from Flow.aspx to my page, the selecteditem in
dropdownlist is still the one I had selected, which is expected, BUT
the html code if I do 'View Source' is:

<option selected="selected" value="13808">DataPage6</option>
<option value="13805">DataPage5</option>
<option value="13489">DataPage4</option>

even if the selecteditem is DataPage5 or DataPage4. It doesn't make
sense to me.
Can you help ?

Eliyahu Goldin

unread,
Mar 7, 2006, 8:02:22 AM3/7/06
to
Normally, the Back button doesn't cause the page to re-load. It gets it from
a local cache. You have to take special care to get the page to reload.

Eliyahu

"sam" <samuelb...@googlemail.com> wrote in message
news:1141732039.9...@i39g2000cwa.googlegroups.com...

sam

unread,
Mar 7, 2006, 8:17:57 AM3/7/06
to
I know that. But can you help me a bit further please. What 'special
care' should I take ?

Eliyahu Goldin

unread,
Mar 7, 2006, 8:33:43 AM3/7/06
to
I didn't do it myself. If you google on something like

"back button" reload page asp.net

you will find a lot of suggestions.

Eliyahu

"sam" <samuelb...@googlemail.com> wrote in message

news:1141737477.7...@j52g2000cwj.googlegroups.com...

sam

unread,
Mar 7, 2006, 9:13:18 AM3/7/06
to
still.... i found that really strange. Did you read my first post ??
The fact that the selected option in the html source code (generated
html from asp server control) does not match the one selected by the
user, is rather strange...

the only way i found on the web is to disable caching, but this is
quite inefficient. I'm quite amazed that there is no simple way to
achieve what I want, without making any compromises such as disabling
caching.

Eliyahu Goldin

unread,
Mar 7, 2006, 9:30:05 AM3/7/06
to
> still.... i found that really strange. Did you read my first post ??
> The fact that the selected option in the html source code (generated
> html from asp server control) does not match the one selected by the
> user, is rather strange...

That's the whole point! You are dealing with the following scenario:

1. User loads the page from the server. This selects the option specified in
the code.

2. User makes another option selected.

3. User moves out from the page. The page remains cached in the browser
cache with the option selected by the user.

4. User hits the "Back" button. The browsers gets the page from the browser
cache with the option selected by the user. It DOES NOT load the page from
the server.

Eliyahu


sam

unread,
Mar 7, 2006, 9:49:18 AM3/7/06
to
so?
I know that, all I'm saying is that when the use selected the value in
the list this triggers a postback, therefore I would expect the
selected option to change from 0 to whatever index was selected in the
list .... no ?

Eliyahu Goldin

unread,
Mar 7, 2006, 9:53:22 AM3/7/06
to
Didn't you say you redirected to another page? Your postback doesn't result
in rendering the page again, does it?

Eliyahu

"sam" <samuelb...@googlemail.com> wrote in message

news:1141742958.3...@u72g2000cwu.googlegroups.com...

sam

unread,
Mar 7, 2006, 10:11:13 AM3/7/06
to
correct. But here's my understanding:

1. user select a value
2. postback
3. selectedindexchanged event handler called
4. user redirected
5. user browses back to the page.

On 5. the page is loaded from cache, i agree. But to me it is clear
that the page in cache should be the one that was created in 2. and it
should know about the new selected index.

If not, and if the only way to achieve what i want is through forcing
reloading by not caching the page, then can you help me for that ? I've
tried the following code to force expiration of the page, but it only
works with IE, it does not work with Mozilla or Netscape :

<%
Response.CacheControl = "no-cache"
Response.AddHeader("Pragma", "no-cache")
Response.ExpiresAbsolute = DateTime.Now.Date
Response.Expires = -1

%>

Eliyahu Goldin

unread,
Mar 7, 2006, 10:15:59 AM3/7/06
to
How do you redirect?

I can't advice you on other browsers. So far I have being blessed with the
customers who are happy with IE only. Ask this question in a separate
thread.

Eliyahu

"sam" <samuelb...@googlemail.com> wrote in message

news:1141744273.7...@p10g2000cwp.googlegroups.com...

sam

unread,
Mar 7, 2006, 10:28:41 AM3/7/06
to
>How do you redirect?

Just a simple Response.Redirect("anotherpage.aspx") in the
SelectedIndexChanged event handler of my dropdownlist.

>I can't advice you on other browsers. So far I have being blessed with the
>customers who are happy with IE only. Ask this question in a separate
>thread.

lucky you...

Russell

unread,
Mar 8, 2006, 9:11:49 AM3/8/06
to
On your postback you are calling Response.Redirect.

This means the browser gets sent an HTTP header with a redirect
instruction and no body rather than "the page that was created at step
2." No HTML was ever rendered and sent to the browser at all, just the
redirect header.

>But here's my understanding:

> 1. user select a value
> 2. postback
> 3. selectedindexchanged event handler called
> 4. user redirected
> 5. user browses back to the page.


> On 5. the page is loaded from cache, i agree. But to me it is clear
> that the page in cache should be the one that was created in 2. and it
> should know about the new selected index.

sam

unread,
Mar 8, 2006, 9:54:15 AM3/8/06
to
yep, so what do you suggest then ? :-)

Russell

unread,
Mar 13, 2006, 11:10:40 AM3/13/06
to
You could use an "Expires" header (Response.Expires or
Response.AppendHeader) to force page reload on browser back. You'd
also need to cache the dropdown selected value in Session so you could
check for and restore it on the reload.

0 new messages