简体   繁体   中英

Enable an Ajax ComboBox using either javascript or server side C# code

I have an ASP.Net application with a dropdownlist and an Ajax ComboBox. I need to enable/disable the ComboBox depending on the item chosen in the dropdownlist. I've tried this both using client-side javascript and C# server side code. I've tried this in javascript to enable the ComboBox, using the onchange event:

var IMEI = $find("<%=cbIMEI.ClientID %>");
IMEI._element.disabled = false;
IMEI._element.isContentEditable = true;
IMEI._element.isDisabled = false;

None of these methods enabled the ComboBox. I've also tried this on the server side, using the OnSelectedIndexChanged event:

cbIMEI.Enabled = enabled;

This works, sort of. The problem here is that it doesn't work the first time the dropdownlist value is changed, but it will work the 2nd time the value changes. When I walk through the code in the debugger, it tells me the ComboBox is enabled after the first value change, but it remains grayed out and can't be clicked on until I change the value again. Can anyone tell me how to do this?

I stumbled on how to solve this problem by trial and error. Instead of

var IMEI = $find("<%=cbIMEI.ClientID %>");

I used

var IMEIID = '<%= cbIMEI.ClientID %>';
var IMEI = document.getElementById(IMEIID);

Doing this,

IMEI.disabled = false;

works perfectly. I don't at all understand why, but there it is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM