1

Assuming that I can't modify the code-behind file for a site (it's a compiled site), I've encountered a bug of mine that can only be fully fixed with a complete recompile and redeployment. Unfortunately, we are on a strict release schedule and we can't deploy for another 11 days.

The bug is that I'm doing a check on a drop down to make sure that the value that is selected isn't "-1". However, I didn't use drp.SelectedItem.Value, I used drp.Items[0].Value. Total bonehead move on my part. The bottom line is that drp.Items[0].Value is ALWAYS -1, so they page gives an error to the user stating that they need to choose an option for that drop down. Which they really have, but my bug is not letting them continue in this process.

Because I'm an idiot.

So, I'm trying to determine if I could, client-side, replace the value of the first drp item to the actually chosen value of that drop down.

I've gotten this all to work client-side, but when the form is posted back, the value is still the value that was populated from code, meaning "-1".

I'm sure this is because the drop down is loaded and all the values are held in ViewState.

Can anyone think of a .Net friendly solution to this? I'm really hoping there is one.

1 Answer 1

0

Unfortunately, when browser makes the postback, all controls are recreated with default values and then update their values from viewstate and post values. And DropDownList control doesn't update ListItems' values from another collection of values. If we change ListItem's value on client side by javascript, at server side our control will contain default values in its collection of ListItem, in our case it's -1.

Best regards, Dima.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.