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

dropdown list maintains selection when back button is used.

P: n/a
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value
property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You press
the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown is
still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select
the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because
the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using
the same code.

Any ideas??? I would love the second scenario to be the default behavior in
all cases.

Thanks in advance.

Mark
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Drat. For good or for bad, you can easily recreate this on your own. I'd
LOVE to find a work around for this.

All you need to do is create a new web form, and add 2 dropdowns and a
checkbox. Make the id of the checkbox be "ckRedirect":

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add(new ListItem("1","a"));
DropDownList1.Items.Add(new ListItem("2","b"));
DropDownList1.Items.Add(new ListItem("3","c"));

DropDownList2.Items.Add(new ListItem("4","d"));
DropDownList2.Items.Add(new ListItem("5","e"));
DropDownList2.Items.Add(new ListItem("6","f"));

DropDownList1.AutoPostBack = true;
DropDownList2.AutoPostBack = true;
}
}
private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Response.Write("<br>DDL1 selected index fired.");
if (ckRedirect.Checked)
Response.Redirect("http://www.cnn.com/");
}

private void DropDownList2_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Response.Write("<br>DDL2 selected index fired.");
if (ckRedirect.Checked)
Response.Redirect("http://www.aol.com/");
}
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown is still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select
the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because
the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using
the same code.

Any ideas??? I would love the second scenario to be the default behavior in all cases.

Thanks in advance.

Mark

Nov 18 '05 #2

P: n/a
Doubly interesting ... if you turn tracing ON and display it on the page
using your web.config file, this behavior goes away!

????

Ideas?

Thanks in advance.

Mark
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown is still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select
the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because
the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using
the same code.

Any ideas??? I would love the second scenario to be the default behavior in all cases.

Thanks in advance.

Mark

Nov 18 '05 #3

P: n/a
Hi Mark,

When a user hits the back button the page does not go back to the server.
It is shown in the same state as the user left it. Internet Explorer even
returns them to the same position on the page they had scrolled to before
leaving. In order to make this work you need to find out if an event fires
client-side when the page is re-displayed using the back button. If there
is one, then put your client-side code in there to reset your dropdowns. I
don't know of one off the top of my head but if I get a chance I'll look
into it. This should set you on the right path though. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown is still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select
the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because
the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using
the same code.

Any ideas??? I would love the second scenario to be the default behavior in all cases.

Thanks in advance.

Mark

Nov 18 '05 #4

P: n/a
Hi Mark,

It appears that the onload() event fires after the back button takes you to
the previous page. Add the onload() event to your <body> tag and when it
fires reset your drop down lists with client-side javascript. Then you
should be all set. Good luck! Ken.

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Mark,

When a user hits the back button the page does not go back to the server.
It is shown in the same state as the user left it. Internet Explorer even
returns them to the same position on the page they had scrolled to before
leaving. In order to make this work you need to find out if an event fires client-side when the page is re-displayed using the back button. If there
is one, then put your client-side code in there to reset your dropdowns. I don't know of one off the top of my head but if I get a chance I'll look
into it. This should set you on the right path though. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both
dropdowns, when you select an item from the list, it redirects to the Value
property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You

press
the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown

is
still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now select the OTHER dropdown list), *both* dropdown lists selected indexed changed
events fire. Or more precisely, one fires but the other does not because the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using the same code.

Any ideas??? I would love the second scenario to be the default

behavior in
all cases.

Thanks in advance.

Mark


Nov 18 '05 #5

P: n/a
i like this idea a lot. thanks! HOWEVER, my gut wonders if the onload()
event would cause problems when you select an item from the Dropdown each
time. When the page posts back, the onload() would fire and wipe out what
the user selected. I'm nervous the dropdown code would then fire, but use
the incorrect (default) value??

Just typing theoretically here ... thanks again.

mark
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
Hi Mark,

It appears that the onload() event fires after the back button takes you to the previous page. Add the onload() event to your <body> tag and when it
fires reset your drop down lists with client-side javascript. Then you
should be all set. Good luck! Ken.

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Mark,

When a user hits the back button the page does not go back to the server.
It is shown in the same state as the user left it. Internet Explorer even returns them to the same position on the page they had scrolled to before leaving. In order to make this work you need to find out if an event

fires
client-side when the page is re-displayed using the back button. If there is one, then put your client-side code in there to reset your dropdowns.

I
don't know of one off the top of my head but if I get a chance I'll look
into it. This should set you on the right path though. Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the

Value
property of the dropdown. Nothing fancy.

Let's say you select 1 of the items, and are properly redirected. You

press
the back button. I have three servers providing two different
functionalities:

1. After pressing the back button, the item you selected in the dropdown
is
still selected.
2. After pressing the back button, the default item in the dropdown is
selected again.

In the scenario number 1, if you postback again (let's say you now

select the OTHER dropdown list), *both* dropdown lists selected indexed
changed events fire. Or more precisely, one fires but the other does not

because the first one redirects before the second can fire.

I have copied the .dll and .aspx pages several times to confirm I am using the same code.

Any ideas??? I would love the second scenario to be the default

behavior
in
all cases.

Thanks in advance.

Mark



Nov 18 '05 #6

P: n/a
Hi Mark,

If your page posts back to the server and instead of redirecting to another
page displays itself again, then this would cause a problem. You will need
to keep some type of state to know when to actually run the code in your
onload event. The easiest way would be to create a hidden HTML input field
with the runat="server" attribute set. If your page posts back to itself
and needs to keep the current drop down state then set this value to 1 on
the server side code. In the function you call from the onload event check
this field. If it is 0 then reset your list boxes. If it is 1 then ignore
the listboxes and instead reset this variable to 0. You need to do the
reset to 0 client-side because if you did it server side and then to a
redirect it would never get back to your page and when they hit the back
button the value would still be 1 and the list boxes wouldn't reset. Good
luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
i like this idea a lot. thanks! HOWEVER, my gut wonders if the onload()
event would cause problems when you select an item from the Dropdown each
time. When the page posts back, the onload() would fire and wipe out what
the user selected. I'm nervous the dropdown code would then fire, but use
the incorrect (default) value??

Just typing theoretically here ... thanks again.

mark
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
Hi Mark,

It appears that the onload() event fires after the back button takes you

to
the previous page. Add the onload() event to your <body> tag and when it
fires reset your drop down lists with client-side javascript. Then you
should be all set. Good luck! Ken.

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Mark,

When a user hits the back button the page does not go back to the server. It is shown in the same state as the user left it. Internet Explorer even returns them to the same position on the page they had scrolled to before leaving. In order to make this work you need to find out if an event

fires
client-side when the page is re-displayed using the back button. If there is one, then put your client-side code in there to reset your dropdowns. I
don't know of one off the top of my head but if I get a chance I'll
look into it. This should set you on the right path though. Good luck!

Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
> I have two dropdown lists. Both have autopostback set to true. In both > dropdowns, when you select an item from the list, it redirects to the Value
> property of the dropdown. Nothing fancy.
>
> Let's say you select 1 of the items, and are properly redirected. You press
> the back button. I have three servers providing two different
> functionalities:
>
> 1. After pressing the back button, the item you selected in the dropdown is
> still selected.
> 2. After pressing the back button, the default item in the dropdown is > selected again.
>
> In the scenario number 1, if you postback again (let's say you now

select
> the OTHER dropdown list), *both* dropdown lists selected indexed changed > events fire. Or more precisely, one fires but the other does not

because
> the first one redirects before the second can fire.
>
> I have copied the .dll and .aspx pages several times to confirm I am

using
> the same code.
>
> Any ideas??? I would love the second scenario to be the default

behavior
in
> all cases.
>
> Thanks in advance.
>
> Mark
>
>



Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.