Find button on toolbar

11 posts, 0 answers
  1. Dmitry
    Dmitry avatar
    121 posts
    Member since:
    Jul 2010

    Posted 09 Dec 2011 Link to this post

    Hello,
    First I tried to access button by its index, i.e. toolbar.getAllItems()[3]. That worked for some time. But when 1st button is not a button but a dropdown with more buttons in it, that method returns wrong button. Next I tried to access buttons by value. That also worked for some time. But on buttons which may contain child items, like RadToolBarDropDown, that method won't work. Now what do I have to do? Search button by text? My buttons don't have a text at all. So what now?

    PLEASE tell me is that a so HUGE problem do add a simple ID property to each button and implement FindButtonByID method? Is that a feature which requires a deep planning? You are developing this control so long and you can't implement this simplest feature? I can't believe that.
  2. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 09 Dec 2011 Link to this post

    Hi Dmitry,

    Can you please clarify if you are trying to find the button on the client-side or on the server side? In case you need on the server side I would suggest that you take a look at the following forum post where it is both explained and exemplified how this could be achieved:
    http://www.telerik.com/community/forums/aspnet-ajax/toolbar/cannot-find-items-in-radtoolbar-when-a-radtoolbardropdown-is-in-the-collection.aspx#1703176 

    Greetings,
    Kate
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dmitry
    Dmitry avatar
    121 posts
    Member since:
    Jul 2010

    Posted 09 Dec 2011 Link to this post

    That was all on server side. As for your link, RadToolBarDropDown does not have Value property and I cannot find it. Neither I have a text on it, nor I have any url associated with it. That's the button I need to find because I'm going to add child buttons to it at runtime.
  5. Dmitry
    Dmitry avatar
    121 posts
    Member since:
    Jul 2010

    Posted 13 Dec 2011 Link to this post

    Can you please help me with my issue?
  6. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 13 Dec 2011 Link to this post

    Hi Dmitry,

    You could find the specific button by its index value. For instance using the code below you can set visible false to the first button of the RadToolBar control:
    <telerik:RadToolBar runat="server" ID="toolbar1">
            <Items>
                <telerik:RadToolBarButton Text="button1">
                </telerik:RadToolBarButton>
                <telerik:RadToolBarButton Text="button2">
                </telerik:RadToolBarButton>
            </Items>
        </telerik:RadToolBar>

    protected void Page_Load(object sender, EventArgs e)
       {
           toolbar1.Items[0].Visible = false;
       }

    Best wishes,
    Kate
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  7. Stacy
    Stacy avatar
    98 posts
    Member since:
    Dec 2010

    Posted 12 May 2014 Link to this post

    I'd like to know how to find a toolbardropdown on the client side via javascript.  I can find all radbuttons but on the drop down.  I want to find it so I can enable/disable it. 
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 May 2014 in reply to Stacy Link to this post

    Hi Stacy,

    Please have a look into the sample code snippet to access the RadToolBarDropDown from client side.

    ASPX:
    <telerik:RadToolBar ID="RadToolBar" runat="server">
        <Items>
            <telerik:RadToolBarDropDown runat="server" Text="DropDown">
                <Buttons>
                    <telerik:RadToolBarButton Text="Item1">
                    </telerik:RadToolBarButton>
                </Buttons>
            </telerik:RadToolBarDropDown>
        </Items>
    </telerik:RadToolBar>

    JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            var toolbar = $find("<%=RadToolBar.ClientID %>");
            var dropdown = toolbar.findItemByText("DropDown");
            dropdown.disable();
        }
    </script>

    Thanks,
    Princy.
  9. Raymond
    Raymond avatar
    1 posts
    Member since:
    Feb 2014

    Posted 07 Nov 2014 in reply to Dmitry Link to this post

    Hello Dmitry,

    Alternatively, you can find the button by its attribute name.
    (see function: FindItemByAttribute)

    The control does not know 'ID' by itself, but, it does allow you to add it as an attribute.
    Hence in serverside you can retrieve the right button on do as you like. (recurse button under button as you mentioned)

    I hope it helps you or anyone looking for a solution.

    Regards,
    Raymond

  10. Tom
    Tom avatar
    44 posts
    Member since:
    Oct 2010

    Posted 14 Apr Link to this post

    Here is a solution in the case of trying to find a drop down toolbar button on the client side. You can use findItemByAttribute in this way (based on example in this forum post).

    Define your drop down button as such:

    <telerik:RadToolBarDropDown runat="server" Text="Label" key="someValue">

    and then in your script you can find it (assuming you already have found your RadToolBar as "rtbar") with:

    var  ddButton = rtbar.findItemByAttribute("key","mode");

    This information may be in the documentation somewhere, but it was not easy to find. I did not see any specific example that included how to set a drop down attribute and then make a findItemByAttribute call.

     

  11. Tom
    Tom avatar
    44 posts
    Member since:
    Oct 2010

    Posted 14 Apr in reply to Tom Link to this post

    Actually, the JavaScript code should be

    var  ddButton = rtbar.findItemByAttribute("key","someValue");

    Sorry for the error.
  12. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 19 Apr Link to this post

    Hello,

    In addition to findItemByAttribute(), the findItemByValue() method can also be used to find a button on the client, for example:
    var button = toolbar.findItemByValue("5");

    You can find these two and other client-side methods of the RadToolBar object in the following documentation article.

    Regards,
    Ivan Danchev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017