don't use webforms

one, of many, problems with webforms is how it wants to make a stateless enviornment stateful.
A postback validates itself against the "previous" response ensuring that the form was not maliciously altered. part of this validation is checking an option selected by the user from a list/dropdown was part of the "previous" response. This information is stored in the viewstate. By changing these values on the client the viewstate still has the old values which are used to validate the postback. make sense?
if all you want is the new value of the selected item you can try:
1. keep your existing client code. when you extract the value on postback, pull the value from Request.Form["client name of control"), instead of MyDropDownList.SelectedValue. now this gets ugly because you need to build the client name (not id). so it would end up looking something like this
Code:
var clientId = MyDropDownList.ClientId;
var clientName = clientId.Replace("id separator", "name separator");
var value = Request.Form[clientName];
2. make the changes on the server instead of the client. This is poor option even with the use of MS AJAX UpdatePanel(s) because you need to submit a full postback (wrapped in ajax) for every change.
3. Try disabling, validate view state (or something like that). This is along the same lines as utilizing a
Cascading Dropdown List with MS AJAX. there is a property on the page you need to set to false. This will bypass validating the postback is valid.
I'm not 100% sure about this, but it might be possible. Worth a shot anyway.
there is a 4th option... don't use webforms in favor of an MVC framework where you control the html.
however if you change the text of an option and you want to pull that value
Code:
var newText = MyDropDownList.SelectedItem.Text;
that's not possible. with or without webforms. The text of an option is like a label. it's read-only data that is not meant to be altered.
Instead you would need to do this:
1. keep the js you have to change the text of the Option.
2. after the value is changed, add an ajax call to update the data this Option represents on the server.
3. when the form is submitted get the value of row. query the data source (database, file, web service, in memory list, etc) for the new text value based on the id.
Jason Meckley
Programmer
Specialty Bakers, Inc.
faq855-7190
faq732-7259