Enabling/disabling CascadingDropDown using jquery

∥☆過路亽.° 提交于 2019-12-12 06:14:06

问题


Greeting;

I have asp.net dropdownlist control with Ajax CascadingDropDown control.

I also I have asp.net checkbox control. I want to enable/disable CascadingDropDown when the checkbox checked/unchecked using jquery.

I tried diffrent ways but they did not work and if I want to set enable property for the dropdownlist to false it will not work so I have to set the CascadingDropDown enable property to false to disable it but I do not know how.

this is one of the code I tried:

<asp:CheckBox ID="chkWF" runat="server"  onclick="enableDDL"/>

<asp:DropDownList ID="WF" runat="server"></asp:DropDownList>

<cc1:CascadingDropDown ID="WF_CascadingDropDown" runat="server" 
                    TargetControlID="WF" 
                    Category="WF"  
                    LoadingText="Please Wait ..." 
                    PromptText="Select Work Field ..." 
                    ServiceMethod="GetWorkField" 
                    ServicePath="../ServiceTags.asmx" Enabled="True">
                </cc1:CascadingDropDown>






function enableDDL() {

             $('#<%= chkOccup.ClientID %>').click(function() {
                 if ($('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled') != true)
                     $('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled', true);
                 else
                     $('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled', false);

                     });

         }

回答1:


Instead of defining a bool value for the disabled attribute just use the string "disabled" and to enable it, just remove the attribute.

function enableDDL() {
    $('#<%= chkOccup.ClientID %>').click(function() {
        if ($('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled'))
            $('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled', 'disabled');
        else
            $('#<%= WF_CascadingDropDown.ClientID %>').removeAttr('disabled');
     });
}

If that doesn't work, are you sure the result of $('#<%= WF_CascadingDropDown.ClientID %>') is a select element?



来源:https://stackoverflow.com/questions/3533824/enabling-disabling-cascadingdropdown-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!