views:

598

answers:

4

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.

+2  A: 

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.

Ed Woodcock
Have you got any example how can i implement this with javascript?
David Bonnici
http://blog.techsaints.com/2007/05/06/javascript-how-to-get-selected-item-in-dropdown-select-list/ is a good example, I'd just post the code but that's cheating =]
Ed Woodcock
A: 

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
}
Corey Downie
+2  A: 

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.

Jason Jackson
+1  A: 

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

string selectedID = Request[DropdownControl.UniqueID];
Gord