J. Ed
J. Ed

Reputation: 6752

ASP.net server side ListBox controls - get value when a control is disabled

In our project we use ASP.net server-side controls (not my idea).
We have some client-side code that might disable some of those controls.
However, I'm unable to retrieve the SelectedValue of listboxes which have been disabled:

If ListboxA is disabled on the client side, then on postback, ListboxA.SelectedValue is empty (even though there is a selected value). if the listbox is not disabled- the selected value is returned correctly.
I found a workaround for this by simply enabling all the controls before postback, but that's... kinda stupid. anybody got a better idea?

P.S: example scenario: if a user chooses 'administrator' in the 'user type' listbox, the 'permissions' listbox has the value 'all' set, and becomes disabled, so that administrator can only be created with all permissions.

Upvotes: 1

Views: 653

Answers (1)

Cameron S
Cameron S

Reputation: 2301

When the control is disabled, the client will not post the value back to the server, so you cannot retrieve the value that way. This would be better than the client sending data for disabled controls when we don't need it, so the workaround is not "stupid".

However, you have two (probably more) workarounds:

  1. Re-enable the control just before Postback.
  2. Save the value in a hidden field.

Upvotes: 1

Related Questions