Search code examples
javascripttelerikasp.net-ajaxmaxlengthradtextbox

How can we set and then reset MaxLength property for a Telerik TextBox from client side?


I am using a RadTextBox control and I need to set an reset MaxLength property based on some conditions, in client side.

    if(maxLengthToSet == 4){ 
       txtBox.set_maxLength(4);
    }
    else{
       // reset maxlength so that it can accept up-to limits of a RadTextBox
    }

How can we reset the maxLength property or remove this property from the textBox.


Solution

  • We have already solved this at the Telerik ticketing system.

    I am sharing the solution here for your fellow developers:

    if (maxLengthToBeSet == 4) {
       textBox.get_element().setAttribute('maxLength', 4)
    }
     else {
       textBox.get_element().removeAttribute("maxLength");
    }