简体   繁体   中英

ComboBox disabled with C# enable with js

I have an ASPxComboBox which is disabled via C# code and I want to enable it with js Code, but sadly it doesn't work.

Here is what I do: At first I disable it

comboBox.Enabled = false;

Then after a client side selectedItemchanged event is called I call a js function

comboBox.SetEnabled(true);

There is no problem entering the function and if the comboBox isn't disabled in the C# code it is no problem at all dis-/enabling it via js.

Is there a different way how I should approach this?

EDIT: I create the ASPxComboBox hardcoded like this

ASPxComboBox comboBox = new ASPxComboBox();

then I add the clientInstancename to have acces via js code (and ID)

comboBox.ID= "comboBox";
comboBox.ClientInstanceName = comboBox.ID;

Try this >

$("#comboBox").attr("enabled", true);  // To enabled

$("#comboBox").attr("disabled", true); // To disabled

OR

document.getElementById("comboBox").enabled = true; // To enabled 

document.getElementById("comboBox").disabled = true;// To disabled

Edit For ASPxComboBox , you should use SetEnabled() .

document.getElementById("comboBox").SetEnabled(true);
document.getElementById("comboBox").SetEnabled(false);

Reference this How to enable / disable controls on the client side via javascript and ASPxClientEditBase.SetEnabled Method .

You can either use C#:

void Page_Load(Object sender, EventArgs e) {
    comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
}
protected void comboBox_SelectedIndexChanged (object sender, eventargs e)
{
    comboBox.Enabled = true;
}

OR
use JQuery:

$('#<%= comboBox.ClientID %>').change(function() {
        $(this).attr("disabled", false);
}

这应该做

$('#<%= comboBox.ClientID %>').removeAttr("disabled");

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