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

Error when removing an item in a dropdown menu

1 Answer 30 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Eduardo
Top achievements
Rank 1
Eduardo asked on 22 Jun 2009, 06:52 PM
HI,

I guess I'm having a similar issue as I had in the RadMenu, but this time in the toolbar. Here is the original post Recreate menu on click.

What I'm doing is adding and removing items dynamically from the client side to a dropdown menu. The code is very similar as the one in the other thread, but I don't clear all the items, I only remove the one I want when the user clicks on another item in the same dropdown menu.

This happens only when I click the item that will be removed. In the following example, try to click the second item in the dropdown.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="toolbarThinLastButton.aspx.cs" Inherits="toolbarThinLastButton" %> 
<%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"
    <title>Untitled Page</title> 
    <script type="text/javascript"
        var number = 0
        function Clicked() { 
            var taskbar = $find("RadToolBar1"); 
            //var dd = taskbar.findItemByText("xxx"); 
            var dd = taskbar.findItemByAttribute("key", "this"); 
 
            taskbar.trackChanges(); 
 
            var dropDownChildButton = new Telerik.Web.UI.RadToolBarButton(); 
            dropDownChildButton.set_text("a button " + number); 
            number++; 
 
            if (dd.get_buttons().get_count() > 1) { 
                // Remove last 
                dd.get_buttons().removeAt(1); 
            } 
             
            // Tooltip 
            dd.get_buttons().add(dropDownChildButton); 
 
            taskbar.commitChanges(); 
        } 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"
        <asp:ScriptManager ID="scriptManager1" runat="server" /> 
    <div> 
        <telerik:RadToolBar ID="RadToolBar1" runat="server" Skin="Office2007" OnClientButtonClicked="Clicked"
            <Items> 
                <telerik:RadToolBarButton Text="button 1" /> 
                <telerik:RadToolBarButton Text="button 2" /> 
                <telerik:RadToolBarButton Text="button 3" /> 
                <telerik:RadToolBarDropDown Text="xxx" key="this"
                    <Buttons> 
                        <telerik:RadToolBarButton Text="add or remove buttons" ToolTip="click me"
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton Text="bla" ToolTip="click me"
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton Text="bla" ToolTip="click me"
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton Text="bla" ToolTip="click me"
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton Text="bla" ToolTip="click me"
                        </telerik:RadToolBarButton> 
                    </Buttons> 
                </telerik:RadToolBarDropDown> 
            </Items> 
        </telerik:RadToolBar> 
    </div> 
    </form> 
</body> 
</html> 
 

Is there something I can do? In the dropdown menu there is no close() method, so I can't do the same as in the menu.

Thanks,
Eduardo



1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 25 Jun 2009, 08:08 AM
Hi Eduardo,

Please modify Clicked() method like this:

 function Clicked() {    
            var taskbar = $find("RadToolBar1");    
            //var dd = taskbar.findItemByText("xxx");    
            var dd = taskbar.findItemByAttribute("key""this");    
    
            taskbar.trackChanges();    
    
            var dropDownChildButton = new Telerik.Web.UI.RadToolBarButton();    
            dropDownChildButton.set_text("a button " + number);    
            number++;    
    
            if (dd.get_buttons().get_count() > 1) {    
                // Remove last    
                setTimeout( function() {dd.get_buttons().removeAt(1); }, 1);   
            }    
                
            // Tooltip    
            dd.get_buttons().add(dropDownChildButton);    
    
            taskbar.commitChanges();    
        }   


Best regards,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ToolBar
Asked by
Eduardo
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or