This is a migrated thread and some comments may be shown as answers.

RadTextBox.isEmpty not working

2 Answers 279 Views
Input
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 27 Apr 2018, 07:59 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 30 Apr 2018, 11:48 AM
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.
0
Keith
Top achievements
Rank 1
answered on 30 Apr 2018, 12:01 PM
What a facepalm moment.  I knew that.  Thank you for your help.
Tags
Input
Asked by
Keith
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Keith
Top achievements
Rank 1
Share this question
or