Articles in this section

How to Change the Enabled State of .NET MVC DropDownList?

In ASP.NET MVC, there may be scenarios where you need to dynamically control the enabled state of a ASP.NET MVC DropDownList component. This can be achieved by accessing the DropDownList instances and toggling the enabled property.

Toggling Enabled State

To access the DropDownList instances, you need to use the component ID. You can use document.getElementById('Your-DropDownList-ID').ej2_instances[0] to get the instance of the DropDownList. Once you have the DropDownList instance, you can toggle the enabled property to enable or disable the DropDownList. You can do this by setting dropDownObj.enabled = !dropDownObj.enabled, where dropDownObj is your DropDownList instance.

Code Example

<div style="margin:150px auto;width:300px">
    @Html.EJS().DropDownList("Sample-ID").Placeholder("Select a Value").DataSource(ViewBag.data).Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "Text", Value = "Value" }).Render()
    <hr />
    <button class="e-btn" onclick="toggleDropDownList()">Toggle DropDownList</button>
</div>

<script>
    function toggleDropDownList() {
        var dropDownObj = document.getElementById('Sample-ID').ej2_instances[0];
        dropDownObj.enabled = !dropDownObj.enabled;
    }
</script>

By following this guide, you should be able to dynamically control the enabled state of the DropDownList component in your ASP.NET MVC applications.

rte_image_186.gif

Conclusion
I hope you enjoyed learning on how to change the enabled state of .NET MVC DropDownList.
You can refer to our ASP.NET MVC DropdownList feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET MVC DropdownList example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied