locked
how to grab the value of filed and compare the value in condition RRS feed

  • Question

  • User355715116 posted

    Hello programmers , 
    I have a textbox with Id of txtCertificate and grabbing the value in c# i want to put a condition that if the value of  txtCertificate is empty i want to show an alert message.How Can i do this? 

    <tr>
                                <td style="padding-top: 5px; width: 150px;">Document Title:
                                </td>
                                <td style="padding-top: 5px;">
                                    <table border="0">
                                        <tr>
                                            <td>
                                                <telerik:RadTextBox ID="txtCertificate" runat="server" ValidationGroup="vgCertificate" Width="361px" MaxLength="50" ClientIDMode="AutoID"
                                                    Text='<%# DataBinder.Eval( Container, "DataItem.Certification" ) %>'>
                                                </telerik:RadTextBox></td>
                                            <td>
                                                <asp:RequiredFieldValidator ID="rfvCertificate" runat="server" ControlToValidate="txtCertificate"
                                                ErrorMessage="Title is Required" ForeColor="#CC0000" ValidationGroup="vgCertificate">*</asp:RequiredFieldValidator></td>
                                        </tr>
                                    </table>
                                </td>
                                <td style="padding-top: 5px;"></td>
                            </tr>

    I've tried in this way, It is not working.

    var documentTitle = $find("<%# txtCertificate.ClientID %>");
                var documentTitleText = documentTitle.value();
    
                if (documentTitleText == "") {
                    alert("Test");
                    preventDefault();
                    return false;
    
                }
                else {
                    return true;
                }

    Thanks in advance. 

    Wednesday, June 3, 2020 8:24 AM

Answers

  • User-719153870 posted

    Hi mazharul007,

    How about use the built-in isEmpty() method rather than =="", please check this detailed sample at Determine if RadTextBox is empty.

    <script type="text/javascript">
                function determineIfEmpty(sender, eventArgs) {
                    var emptyBox = $find('RadTextBox1');
    
                    if (emptyBox.isEmpty()) {
                        alert('Please, enter a not empty value.');
                    }
                    else {
                        alert('Thank you!');
                    }
                }
    </script>

    In addition, Telerik also provide validation controls, please refer to Validation.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 3, 2020 9:47 AM

All replies

  • User-719153870 posted

    Hi mazharul007,

    How about use the built-in isEmpty() method rather than =="", please check this detailed sample at Determine if RadTextBox is empty.

    <script type="text/javascript">
                function determineIfEmpty(sender, eventArgs) {
                    var emptyBox = $find('RadTextBox1');
    
                    if (emptyBox.isEmpty()) {
                        alert('Please, enter a not empty value.');
                    }
                    else {
                        alert('Thank you!');
                    }
                }
    </script>

    In addition, Telerik also provide validation controls, please refer to Validation.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 3, 2020 9:47 AM
  • User355715116 posted

    Thanks Yang , 

    I solved my issue with this 

     var documentTitle = $find("<%# txtCertificate.ClientID %>");
     var documentTitleText = documentTitle.get_value();
    
            if (documentTitleText == null || documentTitleText =="") {
                alert("test");
                preventDefault();
                return false;
    
            }
            else {
                return true;
            }

    Wednesday, June 3, 2020 10:41 AM