Click here to Skip to main content
15,886,137 members
Articles / Programming Languages / C#
Tip/Trick

Kendo UI NumericTextBox Enable/Disable Issue

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
29 Jan 2016CPOL 25.9K   1  
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)


Written By
Software Developer (Senior)
United States United States
I love to code (ASP.NET-C#, SQL, AJAX, HTML, XML, WCF, MVC, JQuery, Kendo, REST Services, Business Analysis are my favourites to work with),play outdoor sports, travel to places, meet new people, be amidst Nature, read inspirational books, listen to music & am a Foodie as well.

Comments and Discussions

 
-- There are no messages in this forum --