tags:

views:

293

answers:

3

Hi, I am pulling my ddl options from a database, which sets the order of the list. How do I keep the selected option to display when I Response.Redirect?

Page loads with Adidas -(ddl list order) Adidas, Nike, Puma

when Nike is selected -(ddl list order) Adidas, Nike, Puma

for Puma - -(ddl list order) Adidas, Nike, Puma

Right now, the redirect resets the displayed option to Adidas. How do I have it change accordingly? thanks

+3  A: 

A response.redirect should clear viewstate, so the only way you'll be able to keep the selected item is to encode it somehow into the new request. Either use a query string (foo.aspx?currentSelectedShoes=Nike) or set a cookie with the same information before your response.redirect.

Then in your page load event handler check for the query string or cookie and set the selected item accordingly.

Randolpho
A: 

Using Server.Transfer instead of Response.Redirect will preserve your current form state, allowing you to store the selected value in a hidden field if you want.

Chris Ballance
+1  A: 

To add to what Randolpho has said, you could also use session state or the ASP.NET profile. These options have caveats but might be the right choice, particularly if the scope of this piece of data is greater than just this particular page.

Matt Peterson
Good point on session state; dunno why I blanked on that.
Randolpho