1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Abnormal expand/collapse behavior in ItemClick event of RadPanelBar

Abnormal expand/collapse behavior in ItemClick event of RadPanelBar

5 posts, 0 answered
  1. Wen_Hsin
    Wen_Hsin avatar
    3 posts
    Registered:
    01 Jun 2010
    05 Jul 2010
    Link to this post

    Hello

    I use 2 way to add RadPanelItems to RadPanelBar(in TelerikComp2 and TelerikComp4 respectively). If I catch the ItemClick event, the behavior in the TelerikComp4 of my example will be abnormal. But behavior of the TelerikComp2 is right.  Is something wrong?

    TelerikComp2

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="TelerikComp2.aspx.vb" Inherits="TelerikComp2" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="Form2" method="post" runat="server">
            <telerik:RadScriptManager ID="ScriptManager" runat="server" />
            <telerik:RadPanelBar runat="server" ID="RadPanelBar1" Skin="Vista">
                <CollapseAnimation Type="None"></CollapseAnimation>
                <ExpandAnimation Type="None"></ExpandAnimation>
            </telerik:RadPanelBar>
        </form>
    </body>
    </html>

    TelerikComp2 code-behind

    Imports System.Data
    Imports Telerik.Web.UI
      
    Partial Class TelerikComp2
        Inherits System.Web.UI.Page
      
        Protected Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Form2.Load
      
            If Not IsPostBack Then
      
                RadPanelBar1.DataSource = CreateTestTable()
                RadPanelBar1.DataFieldID = "ID"
                RadPanelBar1.DataFieldParentID = "ParentID"
                RadPanelBar1.DataTextField = "Text"
                RadPanelBar1.DataValueField = "ID"
                RadPanelBar1.DataBind()
      
            End If
      
        End Sub
      
        Private Function CreateTestTable() As DataTable
      
            Dim table As New DataTable()
            table.Columns.Add("ID")
            table.Columns.Add("ParentID")
            table.Columns.Add("Text")
            table.Columns.Add("URL")
            table.Columns.Add("Tooltip")
            table.Rows.Add(New String() {"1", Nothing, "root 1", "root1.aspx", "root 1 tooltip"})
            table.Rows.Add(New String() {"2", Nothing, "root 2", "root2.aspx", "root 1 tooltip"})
            table.Rows.Add(New String() {"3", "1", "child 1.1", "child11.aspx", "child 1.1 tooltip"})
            table.Rows.Add(New String() {"4", "1", "child 1.2", "child12.aspx", "child 1.2 tooltip"})
            table.Rows.Add(New String() {"5", "1", "child 1.3", "child13.aspx", "child 1.3 tooltip"})
            table.Rows.Add(New String() {"6", "5", "child 1.3.1", "child131.aspx", "child 1.3.1 tooltip"})
            table.Rows.Add(New String() {"7", "5", "child 1.3.2", "child132.aspx", "child 1.3.2 tooltip"})
            table.Rows.Add(New String() {"8", "2", "child 2.1", "child121.aspx", "child 2.1 tooltip"})
            Return table
      
        End Function
      
        'Protected Sub RadPanelBar1_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadPanelBarEventArgs) Handles RadPanelBar1.ItemClick
        'End Sub
      
    End Class

    TelerikComp4

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="TelerikComp4.aspx.vb" Inherits="TelerikComp4" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form4" runat="server">
            <telerik:RadScriptManager ID="ScriptManager" runat="server" />
            <telerik:RadPanelBar runat="server" ID="RadPanelBar1" Width="500" Skin="Vista">
                <CollapseAnimation Type="None"></CollapseAnimation>
                <ExpandAnimation Type="None"></ExpandAnimation>
            </telerik:RadPanelBar>
        </form>
    </body>
    </html>

    TelerikComp4 code-behind

    Imports Telerik.Web.UI
      
    Partial Class TelerikComp4
        Inherits System.Web.UI.Page
      
        Protected Sub form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form4.Load
      
            If Not Page.IsPostBack Then
                Dim cxtStr As String = "context"
      
                Dim Item1 As RadPanelItem = label_DataBinding("Item1", cxtStr)
                RadPanelBar1.Items.Add(Item1)
      
                Dim Item2 As RadPanelItem = label_DataBinding("Item2", cxtStr)
                RadPanelBar1.Items.Add(Item2)
      
                RadPanelBar1.ExpandMode = PanelBarExpandMode.MultipleExpandedItems
            End If
      
        End Sub
      
        Private Function label_DataBinding(ByVal itemStr As String, ByVal cxtStr As String) As RadPanelItem
      
            Dim Item As New RadPanelItem()
            Item.Text = itemStr
      
            Dim CxtPanelItem As New RadPanelItem()
            Dim Cxtlabel As New Label()
            Cxtlabel.Text = cxtStr
            CxtPanelItem.Controls.Add(Cxtlabel)
            Item.Items.Add(CxtPanelItem)
      
            Return Item
      
        End Function
      
        'Protected Sub RadPanelBar1_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadPanelBarEventArgs) Handles RadPanelBar1.ItemClick
        'End Sub
      
    End Class

    Thank you a lot.

    Wen-Hsin chung

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    05 Jul 2010
    Link to this post
    Hello Wen_Hsin,

    Could you elaborate some more about the actual problem? What do you mean by "the behavior in the TelerikComp4 of my example will be abnormal" and what is the expected behavior?

    Do you run the code in the context of Sitefinity page or it is in a normal aspx page?

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Wen_Hsin
    Wen_Hsin avatar
    3 posts
    Registered:
    01 Jun 2010
    05 Jul 2010
    Link to this post
    Hello,

    The expected behavior is when I first click the root item, level 1 items will be expanded. When I click the same root item again, level 1 items will be collapsed. And the abnormal behavior is that the root item can't expand the level 1 itmes.

    I run the code in a normal aspx page. The attachment is shown the project structure of my example.

    Thank you very much.

    Wen-Hsin chung

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    05 Jul 2010
    Link to this post
    Hello Wen_Hsin,

    You could instantiate a template for your Child PanelParItem and there create a  label. Also, when you click on a root PanelItem there is a post back and template or Label controls are cleared, so you have to do this outside of the if loop that checks for PostBack

    sample code

    protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               string cxtStr = "context";
               RadPanelItem itm1 = Parentlabel_DataBinding("parent1", cxtStr);
               RadPanelItem itm2 = Parentlabel_DataBinding("parent2", cxtStr);
               RadPanelBar1.Items.Add(itm1);
               RadPanelBar1.Items.Add(itm2);
           }
     
           RadPanelBar1.ItemClick += new RadPanelBarEventHandler(RadPanelBar1_ItemClick);
     
     
           foreach (RadPanelItem item in RadPanelBar1.GetAllItems())
           {
               if (item.Attributes["isTemplated"] == "true")
               {
                   template = new LabelTemplate();
                   template.InstantiateIn(item);
               }
           }
       }
     
       void RadPanelBar1_ItemClick(object sender, RadPanelBarEventArgs e)
       {
           Response.Write(e.Item.Text);
       }
     
       private RadPanelItem Parentlabel_DataBinding(string itemStr, string cxtStr)
       {
           RadPanelItem RootPanelItem = new RadPanelItem();
           RootPanelItem.Text = itemStr;
           RadPanelItem ChildPanelItem = new RadPanelItem();
          
           ChildPanelItem.Text = "";
           ChildPanelItem.Attributes.Add("isTemplated", "true");
           RootPanelItem.Items.Add(ChildPanelItem);
           return RootPanelItem;
       }
     
       class LabelTemplate : ITemplate
       {
           public void InstantiateIn(Control container)
           {
               Label label1 = new Label();
               label1.ID = "ChildItemLabel";
               label1.Text = "ChildItemLabel";
               label1.Font.Size = 10;
               container.Controls.Add(label1);
           }
       }
     
       private LabelTemplate template;


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Wen_Hsin
    Wen_Hsin avatar
    3 posts
    Registered:
    01 Jun 2010
    06 Jul 2010
    Link to this post
    Hello,

    It works. Thank you a lot.

    Regards,

    Wen-Hsin
Register for webinar
5 posts, 0 answered