Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Kendo UI NumericTextBox Enable/Disable Issue

0.00/5 (No votes)
29 Jan 2016CPOL 27.2K  
Kendo UI NumericTextBox Enable/Disable issue solved

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.

Introduction

This trick will help you sort out the issue of enabling/disabling (for Kendo UI NumericTextBox).

Background

One of the best things of using a Kendo UI NumericTextBox is that you need not write custom validation separately to allow only Numbers (where the user input has to be Numeric) - however there is a caveat - the enable/disable functionality then, is not as simple as in case of a traditional / any other normal Textbox, for that matter. (I learned it the hard way though... after wasting a lot of time!!).

I needed to disable all AgenctFeeOverrides Textboxes when the repfirmDefault was empty.

Using the Code

C#
// Kendo NumericTextBox html
@(Html.Kendo().NumericTextBoxFor(model => model.AgencyFeeOverride)
.HtmlAttributes(new { style = "width: 85px;font-size:10px;line-height:2em;",
id=Model.OrderDetailId.ToString() + "_agencyFeeOverride" })
.Enable(@Model.AgencyFeeDefault != null && 
@Model.IsViewReadOnly.ToString().ToLower() == "false")
.Decimals(4)
)

$(document).ready(function () 
{
    //Get Default value
    var repFirmDefault = $('#RepFirmNameDefault').text();
       
    //Get all AgencyFeeOverrideList
    var agencyFeeList = $('[id*=_agencyFeeOverride]');
    
    //To disable _agencyFeeOverride kendoNumericTextBox 
    if (repFirmDefault=="") 
        {
            for (var i = 0; i < repFirmFeeList.length; i++) 
            {
                var numerictextbox = $(repFirmFeeList[i]).data("kendoNumericTextBox");
                numerictextbox.enable(false);
            }
        }
});

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)