Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

PanelBar / Client-side API


  • RadPanelBar provides a flexible client-side API. You can easily interact with the panelbar in the browser using the panelbar client-side object.

    1. Getting the RadPanelBar client-side object. RadPanelBar creates a client-side object with the ClientID of the panelbar. You can obtain the reference using the following javascript code:
      var panelBar = $find("<%=RadPanelBar1.ClientID%>");		
      
    2. Once you get the client-side object of RadPanelBar, you can use the findItemByText / findItemByValue methods to get the instance of a particular item. Example:
      var panelBar = $find("<%=RadPanelBar1.ClientID%>");
      var item = panelBar.findItemByText("text");
      
    3. When you get the instance of a particular item, you can call the disable() / enable() / expand() / collapse() / etc. methods:
      function toggleItem()
      {
      	var panelBar = $find("<%=RadPanelBar1.ClientID%>");
      	
      	var item = panelBar.findItemByText("text");
      	
      	if (item)
      	{
      		if(!item.get_expanded())
      
      { item.expand();
      } else { item.collapse(); } } else { alert("Item with text '" + text + "' not found."); } }
      To add a new item:
      //create a new item     
      var childItem = new Telerik.Web.UI.RadPanelItem();      
      childItem.set_text("New");
      //add the newly created item to the Items collection of an item's parent
      item.get_parent().get_items().add(childItem); 
      

      To remove an existing item:
      var parentItem = item.get_parent();
      parentItem.get_items().remove(item); 
      

      To disable an existing item:
      item.disable();

    If you want to persist these changes after postback, the methods described below should be used:

    • panelbar.trackChanges();  -indicates that client-side changes are going to be made and these changes are supposed to be persisted after postback.
    • panelbar.commitChanges(); - submits the changes to the server.
    var panelbar = $find("<%=RadPanelBar1.ClientID%>");
    panelbar.trackChanges();
    //add, remove, disable items
    panelbar.commitChanges(); 
    
    Client side changes are available on the server side after postback. You can use the ClientChanges property to access them:
    foreach (ClientOperation<RadPanelItem> operation in RadPanelBar1.ClientChanges)
    {
    	RadPanelItem item = operation.Item;
    
    	switch (operation.Type)
    	{
    		case ClientOperationType.Insert:
    			break;
    		case ClientOperationType.Remove:
    			break;
    		case ClientOperationType.Update:
    			UpdateClientOperation<RadPanelItem> update = operation as UpdateClientOperation<RadPanelItem>;
    			break;
    		case ClientOperationType.Clear:
    			break;
    	}	
    }
    

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>

    <%@ Page Language="vb" CodeFile="DefaultVB.aspx.vb" AutoEventWireup="true" Inherits="Telerik.Web.Examples.PanelBar.ClientSide.ClientSideAPI.DefaultVB" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server"></qsf:HeadTag>
        <style type="text/css">
            .controlPanel
            {
                margin-top: 20px;
                border: 1px solid #C7E4F4;
                background: #F9FDFE;
                float: left;
                padding: 20px;
            }
            
            .controlPanel dt,
            .controlPanel dd
            {
                float: left;
                height: 40px;
                margin: 0;
                padding: 0;
            }
            .controlPanel dt
            {
                clear: left;
                margin-right: 10px;
                padding-top: 2px;
            }
            
            .inputBox
            {
                border: 1px solid #a7c4d4;
            }
        </style>
    </head>
    <body class="BODY">

        <script type="text/javascript">
        var _persist = true;
        
        function OnClientItemClicked(sender,args)
        {
            var item = args.get_item();
            
            if (item.get_level() == 0)
            {
                return;
            }
            
            var parentItem = item.get_parent();
        
            switch (parentItem.get_text())
            {
                case "Add At Runtime":
                    AddItem(item);break;
                case "Remove At Runtime":
                    RemoveItem(item);
                    break;
                case "Disable At Runtime":
                    DisableItem(item);break;
            }
        }
        function AddItem(item)
        {
            var panel = $find("RadPanelBar1");
            
            if (_persist)
         {
                panel.trackChanges();
            }
            
            var childItem = new Telerik.Web.UI.RadPanelItem();
            
            childItem.set_text("New" + item.get_text());
            
            item.get_parent().get_items().add(childItem);
            
            if (_persist)
         {
                 panel.commitChanges();
            }
        }
        
        function RemoveItem(item)
        {
            var panel = $find("RadPanelBar1");
            var parentItem = item.get_parent();
            
            if (_persist)
         {
                 panel.trackChanges();
            }
        
            parentItem.get_items().remove(item);
            
            if (_persist)
         {
                 panel.commitChanges();
            };
            
        }
        
        function DisableItem(item)
        {
         var panel = $find("RadPanelBar1");
        
         if (_persist)
         {
                 panel.trackChanges();
            }
            
            item.disable();
            
            if (_persist)
         {
                 panel.commitChanges();
            }
        }
        
        function OpenItem()
        {
            var panelbar =$find("RadPanelBar2");
            var text = document.getElementById("openTextBox").value;
            
            var item = panelbar.findItemByText(text);
            
            if (item)
            {
                item.expand();
            }
            else
            {
                alert("Item with text '" + text + "' not found.");
            }
        }
        
        function CloseItem()
        {
            var panelbar = $find("RadPanelBar2");
            var text = document.getElementById("closeTextBox").value;
            
            var item = panelbar.findItemByText(text);
            
            if (item)
            {
                item.collapse();
            }
            else
            {
                alert("Item with text '" + text + "' not found.");
            }
        }

        function Persist()
        {
            _persist = !_persist;
        }
        </script>

        <form id="mainForm" method="post" runat="server">
            <telerik:RadScriptManager ID="ScriptManager" runat="server" />
            <qsf:Header ID="Header1" runat="server" NavigationLanguage="VB"></qsf:Header>
            <div style="height: 300px;">
                <div class="title">Add/Remove/Disable items</div>
                
                <div style="float: left; margin: 13px 80px 0 0;">
                    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Height="250px" OnClientItemClicked="OnClientItemClicked" ExpandMode="FullExpandedItem" />
                </div>
                <div class="controlPanel" style="width: 350px;">
                    <asp:CheckBox runat="server" id="Checkbox2" checked="True" onclick="Persist();" Text="Persist changes after postback" />
                    <br /><br />
                    <asp:Button runat="server" ID="Button1" Text="PostBack..." OnClick="Button1_Click" CssClass="qsfButtonBigger" />
    <asp:TextBox runat="server" ID="TextBox1" Width="330px" TextMode="multiLine" Rows="8"
    Columns="14"></asp:TextBox>

                </div>
            </div>
            
            <div style="height: 300px;">
                <div class="title">Opening/Closing items</div>
                
                <div style="float: left; margin: 13px 80px 0 0;">
                    <telerik:RadPanelBar runat="server" ID="RadPanelBar2" >
                        <Items>
                            <telerik:RadPanelItem Expanded="True" Text="ASP.NET controls">
                                <Items>
                                    <telerik:RadPanelItem Text="RadMenu">
                                    </telerik:RadPanelItem>
                                    <telerik:RadPanelItem Text="RadTabStrip">
                                    </telerik:RadPanelItem>
                                    <telerik:RadPanelItem Text="RadPanelBar">
                                    </telerik:RadPanelItem>
                                    <telerik:RadPanelItem Text="RadTreeView">
                                    </telerik:RadPanelItem>
                                </Items>
                            </telerik:RadPanelItem>
                            <telerik:RadPanelItem Text="WinForms controls">
                                <Items>
                                    <telerik:RadPanelItem Text="RadMenustrip">
                                    </telerik:RadPanelItem>
                                    <telerik:RadPanelItem Text="RadTabStrip">
                                    </telerik:RadPanelItem>
                                    <telerik:RadPanelItem Text="RadToolStrip">
                                    </telerik:RadPanelItem>
                                </Items>
                            </telerik:RadPanelItem>
                            <telerik:RadPanelItem Text="Other projects">
                                <Items>
                                    <telerik:RadPanelItem Text="SiteFinity">
                                    </telerik:RadPanelItem>
                                    <telerik:RadPanelItem Text="Reporting">
                                    </telerik:RadPanelItem>
                                    <telerik:RadPanelItem Text="RadAjax">
                                    </telerik:RadPanelItem>
                                </Items>
                            </telerik:RadPanelItem>
                        </Items>
                    </telerik:RadPanelBar>
                </div>
                <dl class="controlPanel" style="width: 320px;">
                    <dt>
                        <input type="text" id="openTextBox" value="Other projects" class="inputBox" />
                    </dt>
                    <dd>
                        <button class="qsfButtonBigger" onclick="OpenItem();return false;" type="button">Expand item</button>
                    </dd>
                    <dt>
                        <input type="text" id="closeTextBox" value="ASP.NET controls" class="inputBox" />
                    </dt>
                    <dd>
                        <button class="qsfButtonBigger" onclick="CloseItem();return false;" type="button">Collapse item</button>
                    </dd>
                </dl>
            </div>
            
            <qsf:Footer ID="Footer1" runat="server"></qsf:Footer>
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451