Question

How can use a dropdown list without the autopostback=true.

The value on the server is not being changed according to the one selected from the client side. As I already stated I do not wish that for each dropdown I have the autopostback will trigger a post back.

Was it helpful?

Solution

Any time I have lost the value of the drop-down it is because I messed up and repopulated the drop down before handling the value change. For me, it has been drop-downs that I need to do something special with like add item attributes for Javascript, etc. This is data that needs to be added on every page load (aka data that is not persisted in the drop down like the names and values of each item). In these cases I have done this work on load, then I try to retrieve the value later in the page lifecycle and DOH!

Here is the page lifecycle:

http://msdn.microsoft.com/en-us/library/ms178472.aspx

Dollars to donuts that is what is happening. You are probably just reloading the items before you get to handling whatever postback event you are using to grab the value. If you are doing this and cannot get around this work flow, just save the selected index at the beginning of the logic that populates the drop-down, then set the selected index of the drop down with that value when done.

OTHER TIPS

it'll be saved in the viewstate, so the value will be correct when you do eventually post back, and if you're really desperate to get the current value without a postback, javascript would be the way to do this.

Worst case you can grab the value right off the request object:

string selectedID = Request[DropdownControl.UniqueID];

You should make sure you are only filling the select box with options during the initial page load, and not again during the postback

if (!this.Page.IsPostBack) {
  //fill select box here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top