views:

256

answers:

2

Say you have a few DropDownLists that filter data:

Car Make:  [Ford,Chevrolet,etc]
Car Year:  [2010, 2009, 2008, etc]
Car Model: [LT, SLT, etc]

And you make a selection and not show that DDL again. Is there any standard place to maintain previously selected values? This is for a "drill down" menu system.

+2  A: 

You can store in in a hidden field or you could store it in the session. I prefer to keep data out of the session. I'd just stick it in a hidden field and rebuild your state each on each request.

Ryan
A good suggestion. I remember we had trouble getting Session.SessionID to produce the same ID each return, so hidden fields sounds good.
Dr. Zim
Yep, just checked it out. I put Response.Write(Session.SessionID), which keeps putting up a different ID each time I hit refresh, or go to a different link and go back again. It would be nice to know how to keep the same SessionID.
Dr. Zim
Heh, I didn't know you had to store something in the Session for it to keep the same session id. Now that is a working answer!
Dr. Zim
That's good to know about SessionID!
Ryan
+1  A: 

You can use the model to do this. You'll receive the selected values from the user, then just make sure when you pass the model back into the view, it has the previously selected value.

If you're using the Html helpers to render your input controls, it should wire it up for "free".

CubanX
It will map the field names to the Model, but the big question is how to keep that in the Model when that control is missing the second post.
Dr. Zim