Cannot find items in RadToolBar when a RadToolBarDropDown is in the collection

20 posts, 0 answers
  1. Praveen
    Praveen avatar
    8 posts
    Member since:
    Oct 2007

    Posted 23 Jun 2011 Link to this post

    The following code does not work when the toolbar contains any RadToolBarDropDown objects:

    RadToolBar1.Items.FindItemByValue("buttonValue").Visible = true;

    It results in the following exception:

    Value property is not supported by RadToolBarDropDown
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
    Exception Details: System.Exception: Value property is not supported by RadToolBarDropDown

    This makes using it very difficult (indeed impossible).

    I note that this has come up before but it seems like the problem is being ignored

     

  2. Praveen
    Praveen avatar
    8 posts
    Member since:
    Oct 2007

    Posted 29 Jun 2011 Link to this post

    I have submitted this as a bug to the support system, #438803

  3. Kate
    Admin
    Kate avatar
    1898 posts
    Member since:
    Sep 2012

    Posted 29 Jun 2011 Link to this post

    Hello Praveen,

    Unfortunately, I am not able to open the forum (I assume it to be) that you gave a link to. However, to be able to find a Child Button located in RadToolBarDropDown you will only need to use the following code (no need to search in the Items):
    markup:

    <telerik:RadToolBar ID="RadToolBar1" runat="server">
               <Items>
                   <telerik:RadToolBarButton runat="server" Text="Button 0" Value="button1">
                   </telerik:RadToolBarButton>
                   <telerik:RadToolBarButton runat="server" Text="Button 1">
                   </telerik:RadToolBarButton>
                   <telerik:RadToolBarButton runat="server" Text="Button 2">
                   </telerik:RadToolBarButton>
                   <telerik:RadToolBarButton runat="server" Text="Button 3">
                   </telerik:RadToolBarButton>
                    
                   <telerik:RadToolBarDropDown runat="server" Text="DropDown 0">
                       <Buttons>
                           <telerik:RadToolBarButton runat="server" Text="Child Button 1" Value="value1">
                           </telerik:RadToolBarButton>
                           <telerik:RadToolBarButton runat="server" Text="Child Button 2">
                           </telerik:RadToolBarButton>
                       </Buttons>
                   </telerik:RadToolBarDropDown>
               </Items>
           </telerik:RadToolBar>

    code behind:
    protected void Page_Load(object sender, EventArgs e)
       {        RadToolBar1.FindItemByValue("value1").Visible = false;             
            
       }

    Kind regards,
    Kate
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  4. Praveen
    Praveen avatar
    8 posts
    Member since:
    Oct 2007

    Posted 29 Jun 2011 Link to this post

    Thank you Kate, that's ace, thanks!

  5. Garry
    Garry avatar
    39 posts
    Member since:
    Sep 2012

    Posted 06 Mar 2012 Link to this post

    Kate

    I am encountering the same problem.

    I cannot use your workaround because I need access to the .Checked property which is not in the Item base class:

    RadToolBar1.Items.FindItemByValue("groupingEditor").checked
    'checked' is not a member of 'Telerik.Web.UI.RadToolBarItem'.

    Here is my code:

    Dim btn As Telerik.Web.UI.RadToolBarButton = RadToolBar1.Items.FindItemByValue("groupingEditor")
    and here is the response at run-time:
    System.Exception was unhandled by user code
    Message: Value property is not supported by RadToolBarDropDown

    This is raised because there is a drop down on the toolbar and the FindItemByValue function still contains a bug in 2012.1.

  6. Kate
    Admin
    Kate avatar
    1898 posts
    Member since:
    Sep 2012

    Posted 07 Mar 2012 Link to this post

    Hello Garry,

    You need to cast the item to the correct type so you can access the Check property of the control. You can refer to the below example:

    <telerik:RadToolBar ID="RadToolBar1" runat="server" >
            <Items>
                <telerik:RadToolBarDropDown EnableDefaultButton="false" Text="Suspend" runat="server" >
                    <Buttons>
                        <telerik:RadToolBarButton Text="Suspend Projects" runat="server" Value="1" >
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton Text="Suspend Workflows" runat="server">
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton Text="Resume Projects" runat="server">
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton Text="Resume Workflows" runat="server">
                        </telerik:RadToolBarButton>
                    </Buttons>
                </telerik:RadToolBarDropDown>
                <telerik:RadToolBarButton runat="server" Text="button0" Value="2"  >
                </telerik:RadToolBarButton>
                <telerik:RadToolBarButton runat="server" Text="button1">
                </telerik:RadToolBarButton>
                <telerik:RadToolBarButton runat="server" Text="button2">
                </telerik:RadToolBarButton>
            </Items>
        </telerik:RadToolBar>

    code behind:
    protected void Page_Load(object sender, EventArgs e)
        {
            var button1 = (RadToolBarButton)RadToolBar1.FindItemByValue("1");
            button1.Checked = true;
             
             
        }

    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.

  7. Charles
    Charles avatar
    75 posts
    Member since:
    Aug 2008

    Posted 29 Mar 2012 Link to this post

    Is there a way to do this from client-side code? I have a RadToolBarDropDown with several RadToolBarButtons. Most of them I can access from the server side with an OnButtonClick for the toolbar hosting them. But, there is one RadToolBarButton that carries a template with a RadDatePicker within it. Once a date is chosen, the dropdown collapses and I have no choice but to write code in the OnClientDropDownClosing event handler on the client. I can't use the option of not collapsing the dropdown after choosing a date because that would render the other buttons in the dropdown ineffective. Basically, my markup for the toolbar looks something like this:

    <telerik:RadToolBar runat="server" ID="RadToolBar1" OnClientDropDownClosing="DropDownClosing" OnClientButtonClicked="ToolbarButtonClick" OnButtonClick="RadToolbar_ButtonClicked" EnableViewState="false">
        <Items>                             
            <telerik:RadToolBarDropDown EnableDefaultButton="true" ImageUrl="Images/search.gif" DropDownWidth="200px" DefaultButtonIndex="0" Text="View" runat="server">
                <Buttons>
                    <telerik:RadToolBarButton Text="Last 24 Hours" ImageUrl="Images/twentyfourhours.png" runat="server" CheckOnClick="True" Group="Views"></telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Last 3 Days" ImageUrl="Images/notes.gif" runat="server" CheckOnClick="True" Group="Views"></telerik:RadToolBarButton
                    <telerik:RadToolBarButton Text="Last Week" ImageUrl="Images/calendar.gif" runat="server" CheckOnClick="True" Group="Views"></telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Unread" ImageUrl="Images/unread.png" runat="server" CheckOnClick="True" Group="Views"></telerik:RadToolBarButton
                    <telerik:RadToolBarButton Text="Flagged" ImageUrl="Images/followUp.gif" runat="server" CheckOnClick="True" Group="Views"></telerik:RadToolBarButton>   
                    <telerik:RadToolBarButton Value="since" Group="Views" CheckOnClick="True" ImageUrl="Images/windows.png" Text="Since...">                           
                        <ItemTemplate>
                            <table>
                            <tr>
                                <td style="width:40px;"
                                    <img src="Images/windows.png"/>
                                </td>
                                <td>
                                    <telerik:RadDatePicker ID="dtSince" 
                                                               Runat="server"  
                                                               PopupDirection="BottomRight"  
                                                               ZIndex="2000000">
                                         
                                    </telerik:RadDatePicker>                                     
                                </td>
                            </tr>
                            </table>                                    
                        </ItemTemplate>
                    </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Reset View" ImageUrl="Images/search.gif" runat="server" CheckOnClick="True" Group="Views"></telerik:RadToolBarButton>   
                </Buttons>
            </telerik:RadToolBarDropDown>
        </Items>
    </telerik:RadToolBar>

    Ultimately, I want all of the RadToolBarButtons within the RadToolBarDropDown to rrespond to a button click. Since there is no button click for the RadDatePicker within the template, I was hoping to attempt to handle that on the client. Any way out of this problem?

  8. Kate
    Admin
    Kate avatar
    1898 posts
    Member since:
    Sep 2012

    Posted 03 Apr 2012 Link to this post

    Hello Charles,

    One way I can think of is that you use the client-side OnDateSelected event and show the dropdown of the RadToolBar control whenever you select a date. For instance you can use the following code:

    <script type="text/javascript">
            function OnDateSelected() {
                var tb1 = $find("RadToolBar1");
                var dd = tb1.findItemByText("View");
                tb1.set_collapseAnimation('0');
                tb1.set_expandAnimation('0');
                dd.showDropDown();
     
            }
         
        </script>

    markup:
    <telerik:RadDatePicker ID="dtSince" runat="server" PopupDirection="BottomRight" ZIndex="2000000"
            ClientEvents-OnDateSelected="OnDateSelected">                                       </telerik:RadDatePicker>

    All the best,
    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.

  9. Stacy
    Stacy avatar
    84 posts
    Member since:
    Dec 2010

    Posted 22 May 2013 Link to this post

    Is there a way to do a "find" when it is the ToolBarDropDown you want to enable/disable, not just the child buttons?

  10. Kit Cat
    Kit Cat  avatar
    8 posts
    Member since:
    Oct 2010

    Posted 27 May 2013 Link to this post

    Stacy, 

    Try using the get_dropDownElement() as described here or you can also try the approach described in this demo

  11. Stacy
    Stacy avatar
    84 posts
    Member since:
    Dec 2010

    Posted 27 May 2013 Link to this post

    Sorry, what I was looking for was for the "RadToolBarDropDown" with buttons.  I ended up using the pre_render event to find it.

    Also, the "get_dropDownElement()" is not listed in the link you sent so you may need to update your notes.

  12. Stacy
    Stacy avatar
    84 posts
    Member since:
    Dec 2010

    Posted 12 May in reply to Stacy Link to this post

    So I have a toolbar with buttons on it, one of them is a radtoolbardropdown.  How do you go about "finding" this to enable/disable in javascript?  I can find all the other "radtoolbarbuttons" on the toolbar but I cant seem to get it to "find" the dropdown so I can enable/disable it.

  13. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 May in reply to Stacy Link to this post

    Hi Stacy,

    You can use the findItemByText() method to get the instance of a particular item as follows.

    JavaScript:

    var Toolbar = $find("<%=RadToolBar1.ClientID %>");
    var toolbarDropdown = Toolbar.findItemByText("DropDownItem1"); // accessing the toolbar dropdown
    var toolbarButton = Toolbar.findItemByText("ButtonItem1"); //accessing the toolbar button

    Please have a look into the following help help documentation to get more information about RadToolBar and RadToolBarItem client object.

    RadToolBar Client Object
    RadToolBarItem Client Object

    Thanks,
    Shinu.

  14. Stacy
    Stacy avatar
    84 posts
    Member since:
    Dec 2010

    Posted 03 Jul in reply to Shinu Link to this post

    That code returns null for me.  I can find buttons but not the toolbar dropdown

  15. Stacy
    Stacy avatar
    84 posts
    Member since:
    Dec 2010

    Posted 03 Jul Link to this post

    Actually, I can find the dropdown but my issue is due to language, this dropdown wont always have the same text as the users can customize it.  Why is there no way to reference this by ID or something static like most controls?

  16. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Jul in reply to Stacy Link to this post

    Hi Stacy,

    In order to get the Items of RadToolBar try to use the methods findItemByText() or findItemByValue(), will returns the item in the toolbar with the specified text or value respectively. For accessing the controls inside the RadToolBarItem use the method findControl. This is the best approach to accessing controls in the RadToolBar and RadToolBarItem.

    Thanks,
    Shinu.

  17. Stacy
    Stacy avatar
    84 posts
    Member since:
    Dec 2010

    Posted 07 Jul in reply to Shinu Link to this post

    findItemByText wont work as the text will not be the same as users can customize the name of the RadToolbarDropDown.  I cannot use findItemByValue as the RadToolbarDropDown does not contain that attribute.

  18. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Jul in reply to Stacy Link to this post

    Hi Stacy,

    With reference to this forum thread RadToolBarDropDown doesn't have Value attribute. So the way of accessing RadToolbarDropDown from client side is by  using findItemText. Can you please elaborate the statement "user can customize the text", how it is performed?

    Thanks,
    Shinu.

  19. Stacy
    Stacy avatar
    84 posts
    Member since:
    Dec 2010

    Posted 08 Jul in reply to Shinu Link to this post

    We offer a dynamic product with users having the ability to change button text to suit their language so we cannot always trust that the "text" will be the same.  Not sure why this control would not have an ID tag a part of it's design.

  20. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    896 posts
    Member since:
    Aug 2012

    Posted 11 Jul Link to this post

    Hello Stacy,

    Indeed the RadToolBar RadToolBarDropDown does not have Value property and this request is already logged in our system. Here you can track its progress and vote for it. At this point the only solution is to find the item by text.


    Regards,
    Boyan Dimitrov
    Telerik

     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     

Back to Top