RadTextBox.isEmpty not working

3 posts, 1 answers
  1. Keith
    Keith avatar
    26 posts
    Member since:
    Jan 2013

    Posted 27 Apr 2018 Link to this post

    My JS stops functioning after I attempt to find out if a RadTextBox is empty.

     

    01.<telerik:RadTextBox ID="rtbEmptyBox" runat="server" EmptyMessage="This box is empty." />
    02.<telerik:RadButton ID="rbtnDetermineIfEmpty" runat="server" Text="Determine if Empty" AutoPostBack="false" OnClientClicked="determineIfEmpty" />
    03. 
    04.function determineIfEmpty(sender, eventArgs) {
    05.    var emptyBox = document.getElementById('<%=rtbEmptyBox.ClientID %>');
    06. 
    07.    if (emptyBox.isEmpty()) {
    08.        console.log('empty box is empty');
    09.    }
    10.    else {
    11.        console.log('empty box is full');
    12.    }
    13.}

    The JS stops at line 07 and won't proceed.  Do I have the functionality of isEmpty() incorrect?  I'm attempting to get the value of the text box, but when it is empty, it gives me the value of the EmptyMessage.

  2. Answer
    Rumen
    Admin
    Rumen avatar
    14153 posts

    Posted 30 Apr 2018 Link to this post

    Hi Keith,

    RadTextBox is an ASP.NET AJAX server component and you have to get reference to its object via the $find method:

    <telerik:RadTextBox ID="rtbEmptyBox" runat="server" EmptyMessage="This box is empty." />
    <telerik:RadButton ID="rbtnDetermineIfEmpty" runat="server" Text="Determine if Empty" AutoPostBack="false" OnClientClicked="determineIfEmpty" />
    <script>
        function determineIfEmpty(sender, eventArgs) {
            var emptyBox = $find('<%=rtbEmptyBox.ClientID %>');
            
            if (emptyBox.isEmpty()) {
                console.log('empty box is empty');
            }
            else {
                console.log('empty box is full');
            }
        }
    </script>

    This will fix the problem.

    Best regards,
    Rumen
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Keith
    Keith avatar
    26 posts
    Member since:
    Jan 2013

    Posted 30 Apr 2018 Link to this post

    What a facepalm moment.  I knew that.  Thank you for your help.
Back to Top