- Home
- Forum
- ASP.NET MVC - EJ 2
- Is it possible to change the enabled / disabled status of a dropdownlist through a button?
Is it possible to change the enabled / disabled status of a dropdownlist through a button?
Hello, I am working with a dropdownlist with the property enabled in false and I wanted to know if it can be changed to true through a button
Here is my code:
@(Html.EJS().DropDownList("GenreId")
.DataSource(dataManager => dataManager.Url(Url.Action("Genre", "Ext", null, Request.Url.Scheme))
.Adaptor("UrlAdaptor").CrossDomain(true))
.Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings
{
Text = "Name",
Value = "GenreId"
})
.PopupHeight("200px")
.Width("200px")
.Value(Model.GenreId).Enabled(false)
.Render()
)
<button class="btn btn-success" id="btnChange">Change</button>
<script type="text/javascript">
$("#btnChange").click(function(){
var x = document.getElementById("GenreId").ej2_instances[0];
x.element.disabled = false;
x.element.readOnly = false;
x.properties.enabled = true;
});
</script>
I do not know if this is the right way to do it. I hope you can help me.
Thanks in advance
SIGN IN To post a reply.
3 Replies
PO
Prince Oliver
Syncfusion Team
March 22, 2019 05:54 AM UTC
Hello Juan,
Thank you for contacting Syncfusion support.
Yes, it is possible to change the enabled / disabled status of a DropDownList through a button. All you need to do is use the enabled property in the control and set it as true to enable and false to disable it. You can call the dataBind method to reflect the changes immediately in the control. Please refer the below code.
|
$("#btnChange").click(function () {
var x = document.getElementById("GenreId").ej2_instances[0];
if (x.enabled) {
x.enabled = false; // To disable
x.dataBind(); //To affect the changes immediately
} else {
x.enabled = true; // To enable
x.dataBind(); //To affect the changes immediately
}
}); |
Let us know if you have any further queries.
Thanks,
Prince
Thank you! It worked for me.
PO
Prince Oliver
Syncfusion Team
August 26, 2021 07:00 AM UTC
Hi Nicolás,
Most welcome. We are glad that the solution worked in your end.
Regards,
Prince
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
JC Juan Cruz
- Mar 21, 2019 06:42 PM UTC
- Aug 26, 2021 07:00 AM UTC