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

Find button on toolbar

11 Answers 172 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 09 Dec 2011, 02:35 PM
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.

11 Answers, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 09 Dec 2011, 03:22 PM
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
0
Dmitry
Top achievements
Rank 1
answered on 09 Dec 2011, 03:37 PM
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.
0
Dmitry
Top achievements
Rank 1
answered on 13 Dec 2011, 10:33 AM
Can you please help me with my issue?
0
Kate
Telerik team
answered on 13 Dec 2011, 12:42 PM
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
0
Stacy
Top achievements
Rank 1
answered on 12 May 2014, 04:56 PM
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. 
0
Princy
Top achievements
Rank 1
answered on 13 May 2014, 05:07 AM
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.
0
Raymond
Top achievements
Rank 1
answered on 07 Nov 2014, 03:17 PM
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

0
Tom
Top achievements
Rank 1
answered on 14 Apr 2016, 04:07 PM

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.

 

0
Tom
Top achievements
Rank 1
answered on 14 Apr 2016, 04:09 PM

Actually, the JavaScript code should be

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

Sorry for the error.
0
Ivan Danchev
Telerik team
answered on 19 Apr 2016, 10:53 AM
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.
0
Tom
Top achievements
Rank 1
answered on 16 Oct 2018, 02:41 PM
Regarding the "findItemByAttribute" example I posted a couple of years ago, note that the attribute ("key" in my example) is case sensitive. The case used for the attribute in the toolbar item declaration must be the same as in the JavaScript findItemByAttribute method.
Tags
ToolBar
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Kate
Telerik team
Dmitry
Top achievements
Rank 1
Stacy
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Tom
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or