473,388 Members | 936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

dropdown list maintains selection when back button is used.

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
6 10638
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
dmjpro
by: dmjpro | last post by:
i saw some magic web pages ..... when press back button then the same page again and again reloaded ... is it possible in js ...... plz help me out ... thanx in advnace .......
0
by: Frank | last post by:
Hi, I've applied a SSL cert to a portion of my website, which brings the user to an https://mysite/login/Login.aspx page. After successfully logging in, the user can browse around freely in the...
6
by: lucyh3h | last post by:
Hi, In one of my pages, I use javascript (AJAX) to populate one mulitple select field based on user's click event on another control. I noticed that when I navigate back to this page by clicking...
1
by: ARAVIND999 | last post by:
PLEASE SEND THE SOURCE CODE FOR THE ABOVE MENTIONED STATEMENT.(i.e., HOW TO EXPIRE THE PAGE WHEN BACK BUTTON IS PRESSED)
1
by: Rob | last post by:
I know this is an old one, considering how many posts I found on it but I just wondered if any best practises had popped up recently, especially as Ajax has increased JavaScript and DHTML's...
1
rrocket
by: rrocket | last post by:
I have a page with radio buttons that either enable or disable textboxes depending on the radio button selection. When the user clicks submit the they are taken to a thank you page, but if they hit...
1
by: jeet232 | last post by:
Hi, how can I get to know when user clicks browser back button? I want my own javascript code to be executed when this happens. Also, is there a way that whenever any link in the page is clicked,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.