Try our conversational search powered by Generative AI!

Dynamically Populated DropDownList empty on postback


Hi guys,

Basically what I want to do is in my advanced search I'm wanting to be able to search by section, where the user will be able to specify which section to search using a dropdown list.

If I hard code the listitems the search works fine. However, this isn't ideal. I can initally populate the dropdown with the desired items (if !IsPostBack), however when the page is posted, the list empties and doesn't search within the chosen selection.

I've set EnableViewstate to true in the masterpages, and the page itself, but it makes no difference.

If I have the dropdown populated on pageload, it again searches the root rather than the selected item.


Is there anything I'm missing? Its driving me mad!

Aug 12, 2009 18:25

This is classic .NET and related to the Page Lifecycle - to fully understand read this article:

In short: you need to add your items before ViewState is loaded - use the OnInit method (and you need to add the items also on postbacks).

Edited, Aug 13, 2009 10:45

Mari! Got it sorted, can't believe I overlooked this!


Much appreciated, tusen takk

Aug 13, 2009 11:48

Well I'm 6 years late but today this helped me as well! Tusen takk Mari!

Apr 14, 2015 9:19
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.