I have a drop down that is NOT keeping the value that I select. I already check to True the EnableViewState and nothing yet. What may be missing here? Any advise is appreciated.
+4
A:
Check your Page_Load method. Make sure when you populate it and select the default value it is inside an
if(!IsPostBack) { .. . . }
You could be accidentally setting it on each post back, which is why it seems like it is not retaining its value.
David Basarab
2009-09-22 19:22:08
I've made this mistake before.
David
2009-09-22 19:27:28
Thanks a bunch. I was assigning a Request in the page load that was carrying nothing.
2009-09-22 19:51:00
+5
A:
If you're filling it in the Page_Load(), it will get overwritten each time the page loads. If you want the user selection to persist, fill it in the Page_Init(). The viewstate is applied in between the Page_Load and the Page_Init, so this will ensure proper order of execution.
For more info, look up the Page Lifecycle for ASsp.Net.
David Stratton
2009-09-22 19:22:53
A:
where are you binding your Dropsown list? Make sure that you do following:
if(!IsPostBack)
{
//Do your data binding here
}
Neil
2009-09-22 19:29:42