Reset RadTextBox value to default on client

4 posts, 0 answers
  1. Craig Wallace
    Craig Wallace avatar
    118 posts
    Member since:
    Jan 2005

    Posted 11 Oct 2013 Link to this post

    How can I reset a RadTextBox to its configured EmptyMessage value using JavaScript?

    Note, I want to use the property value without having to state it twice.

    Thanks.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Oct 2013 Link to this post

    Hi Craig,

    Please check the following code I tried to clear the RadTextBox content and display the empty message.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server" EmptyMessage="Enter Name">
    </telerik:RadTextBox>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Clear Textbox" AutoPostBack="false"
        OnClientClicked="clearTextbox">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function clearTextbox(sender, args) {
            var radtextbox = $find('<%=RadTextBox1.ClientID %>');
            radtextbox.clear();
        }
    </script>

    Thanks,
    Shinu.
  3. Saif
    Saif avatar
    4 posts
    Member since:
    Jan 2019

    Posted 13 Feb 2019 in reply to Shinu Link to this post

    Is there a way that i can clear all controls from radwizard at once???

     

  4. Rumen
    Admin
    Rumen avatar
    14163 posts

    Posted 13 Feb 2019 Link to this post

    Hello,

    There is no such direct method to get the RadTextBox collection, but you can try the following approach to meet your scenario:


    function GetRadTextBoxes()
    {
        var allRadTextBoxes = [];
        var allRadControls = $telerik.radControls;
        for (var i = 0; i < allRadControls.length; i++)
        {
            var element = allRadControls[i];
            var isRadTextBox = element instanceof Telerik.Web.UI.RadTextBox;
            if (isRadTextBox)
             {
                Array.add(allRadTextBoxes, element);
             }
        }
     alert(allRadTextBoxes.length);
    }

    Once you have all textboxes you can clear them.

    The solution is based on How-to create a javascript array of all particular RadControls on the page.
     

    Best regards,
    Rumen
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top