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

11 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
    27 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
    71 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
    71 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.

Back to Top