Get/set value from RadTextBox on a RadToolBar using Javascript

3 posts, 1 answers
  1. Emil
    Emil avatar
    19 posts
    Member since:
    Oct 2012

    Posted 19 Dec 2012 Link to this post

    I have a search RadToolBar control:
    <telerik:RadToolBar ID="RadToolBar2" runat="server" Width="100%" OnClientButtonClicking="OnClientButtonClicking">
       <Items>
           <telerik:RadToolBarButton runat="server" Text="Button 0">
               <ItemTemplate>
                   <asp:Label ID="Label1" runat="server" Text="Name:"></asp:Label>
                   <telerik:RadTextBox ID="RadTextBox1" runat="server" Width="70" />
                   <asp:Label ID="Label2" runat="server" Text="Surname:"></asp:Label>
                   <telerik:RadTextBox ID="RadTextBox2" runat="server" Width="70" />
                   <asp:Label ID="Label3" runat="server" Text="Age:"></asp:Label>
                   <telerik:RadTextBox ID="RadTextBox3" runat="server" Width="70" />
               </ItemTemplate>
           </telerik:RadToolBarButton>
           <telerik:RadToolBarButton runat="server" CommandName="NewSearch">
           </telerik:RadToolBarButton>
           <telerik:RadToolBarButton runat="server" CommandName="SearchGrid">
           </telerik:RadToolBarButton>
       </Items>
    </telerik:RadToolBar>

    I want to get/set the value of any RadTextBox controls on the toolbar, using Javascript.

    I have this function:

    function OnClientButtonClicking(sender, args) {
       var button = args.get_item();
       if (button.get_commandName() == "NewSearch") {
           //Here is where I want to clear the content of all the RadTextBox controls on the toolbar
       }
       if (button.get_commandName() == "SearchGrid") {
           //Here is where I want to get the content of a RadTextBox control from the toolbar
       }
    }

    Thank you!
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Dec 2012 Link to this post

    Hi Emil,

    Try the following code snippet to achieve your scenario.

    JS:
    <script type="text/javascript">
        function OnClientButtonClicking(sender, args) {
            var button = args.get_item();
            var toolBar = sender;
            var toolbarbutton = toolBar.findItemByText("Button 0")
            var RadTextBox1 = toolbarbutton.findControl("RadTextBox1");
            var RadTextBox2 = toolbarbutton.findControl("RadTextBox2");
            var RadTextBox3 = toolbarbutton.findControl("RadTextBox3");
            if (button.get_commandName() == "NewSearch") {
                //clear the content of all the RadTextBox controls on the toolbar
                RadTextBox1.clear()
                RadTextBox2.clear()
                RadTextBox3.clear()
            }
            if (button.get_commandName() == "SearchGrid") {
                //get the content of a RadTextBox control from the toolbar
                var txt1value = RadTextBox1.get_value();
                var txt2value = RadTextBox2.get_value();
                var txt3value = RadTextBox3.get_value();
            }
        }
    </script>

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Emil
    Emil avatar
    19 posts
    Member since:
    Oct 2012

    Posted 20 Dec 2012 Link to this post

    Thank you, Princy!
Back to Top