Expand Behaviour fix not working with Q1 2009

6 posts, 0 answers
  1. Chris
    Chris avatar
    58 posts
    Member since:
    Jun 2012

    Posted 15 Apr 2009 Link to this post

    Hi, I am using the Q1 2009 release of your amazing controls. I am using the Panel Bar with a sitemap data source (MOSS2007). This leads to me no being able to expand the panels as the top level items have a url set. I have followed the KB article 'Preserve the expand and collapse functionality of an item which has its NavigateUrl property set.' There are a number of thins that don't add up when comparing the example against the Q1 2009 control.

    1. There is no image element to be found in the DOM of the panelbar the expand arrows are just the backgund image of the SPAN tag. This means that the java script function to trap the click fails everytime as there is no ImageElement
    2. The 'panelbar.AllItems.length' fails on each call as 'AllItems' is undefined.
    3. Using the code behind method to add Image and Expanded Image urls doesn't seem to work for me, the only way I could get them to show up was to modify the css as follows :
    1 /* <expand arrows> */ 
    2 /*
    3 .RadPanelBar_ECPanelBar .rpExpandable .rpText,
    4 .RadPanelBar_ECPanelBar .rpExpanded .rpText
    5 {
    6     background-color: transparent;
    7     background-image: url('PanelBar/Expandable.png');
    8 }
    9 */ 
    10 .RadPanelBar_ECPanelBar .rpExpandable .rpText, 
    11
    12     background-colortransparent
    13     background-imageurl('PanelBar/arrow-down.png'); 
    14
    15  
    16 .RadPanelBar_ECPanelBar .rpExpanded .rpText 
    17
    18     background-colortransparent
    19     background-imageurl('PanelBar/arrow-up.png'); 
    20     background-position: 100% 0px !important; 
    21
    22  
    23  
    24 /* </expand arrows> */ 
    25  
    26  

    The 0px is due to the standard value being -467px and hiding the image.

    Please see the markup of the composite control I am making (due to code behind restictions in MOSS this is a much easier way)

    1 <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LeftNav.ascx.cs" Inherits="usercontrols_LeftNav" compilationMode="Always" %> 
    2 <%@ Register assembly="Telerik.Web.UI, Version=2009.1.311.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4"  
    3         namespace="Telerik.Web.UI" tagprefix="telerik" %> 
    4          
    5 <script type="text/javascript">      
    6 function onClicking(sender, eventArgs)      
    7 {      
    8     var target = eventArgs.get_domEvent().target;  
    9     var item = eventArgs.get_item();  
    10     if (target == eventArgs.get_item().get_imageElement())  
    11     {  
    12         if (item.get_expanded())  
    13             item.collapse();  
    14         else  
    15             item.expand();  
    16           
    17         eventArgs.set_cancel(true);  
    18     }  
    19 }      
    20 </script>  
    21  
    22 <telerik:RadAjaxManagerProxy runat="server" ID="rampChild" > 
    23 </telerik:RadAjaxManagerProxy> 
    24 <telerik:RadPanelBar runat="server" ID="rpbVertNav" PersistStateInCookie="true"  
    25      Skin="ECPanelBar"  
    26     ExpandMode="SingleExpandedItem" EnableEmbeddedSkins="false" 
    27     OnClientItemClicking="onClicking" onitemdatabound="rpbVertNav_ItemDataBound"
    28 </telerik:RadPanelBar> 
    1 using System; 
    2 using System.Web; 
    3 using Telerik.Web.UI; 
    4  
    5 public partial class usercontrols_LeftNav : System.Web.UI.UserControl 
    6
    7  
    8     private string _siteMapID = "QuickLaunchSiteMap"
    9  
    10     public string siteMapID { get { return this._siteMapID; } set { this._siteMapID = value; } } 
    11  
    12      
    13     protected void Page_Load(object sender, EventArgs e) 
    14     { 
    15          
    16     } 
    17  
    18     protected override void OnInit(EventArgs e) 
    19     { 
    20         base.OnInit(e); 
    21  
    22         rpbVertNav.DataSourceID = _siteMapID; 
    23     } 
    24  
    25     protected void rpbVertNav_ItemDataBound(object sender, RadPanelBarEventArgs e) 
    26     { 
    27         if (e.Item.Items.Count > 0) 
    28         { 
    29             e.Item.ImageUrl = "arrow-down.png"
    30             e.Item.ExpandedImageUrl = "arrow-up.png"
    31             e.Item.ImagePosition = RadPanelItemImagePosition.Right; 
    32         } 
    33     } 
    34

    This is the js I was trying to use as taken from your sample

    1 <script type="text/javascript">   
    2         <!-- For radPanelBar -->    
    3         function OnLoad(sender, args)      
    4         {      
    5             var panelbar = sender;      
    6              
    7             for (var i = 0; i < panelbar.AllItems.length; i++)      
    8             {      
    9                 var panelItem = panelbar.AllItems[i];      
    10                       
    11                 if (panelItem.ImageElement)      
    12                 {      
    13                     panelItem.ImageElement.AssociatedItem = panelItem;      
    14                     panelItem.ImageElement.onclick = function (e)      
    15                     {      
    16                         if (!e) e = window.event;      
    17                               
    18                         if (this.AssociatedItem.Expanded)      
    19                         {      
    20                             this.AssociatedItem.Collapse();      
    21                         }      
    22                         else     
    23                         {      
    24                             this.AssociatedItem.Expand();      
    25                         }      
    26                               
    27                         e.cancelBubble = true;      
    28                         if (e.stopPropagation)      
    29                         {      
    30                             e.stopPropagation();      
    31                         }      
    32                         return false;      
    33                     }      
    34                 }      
    35             }      
    36         }      
    37         </script>    

    I really want to use this panel bar control for my navigation in this site but i cannot as it will not expand as expected. PLease can you update the sample to work with Q1 2009 or post a 2009 working sample using a sitemapdatasource.

    Many Thanks

    Chris
  2. Chris
    Chris avatar
    58 posts
    Member since:
    Jun 2012

    Posted 15 Apr 2009 Link to this post

    FIXED

    Hi I started playing around more and found out why I was not getting any Image Elements. The code in the ItemDatabound event was not working with either the Q1 2009 control or the sitemap data source. Anyway here is the fix I used to get it going.

    Code behind for ItemDatabound
        protected void rpbVertNav_ItemDataBound(object sender, RadPanelBarEventArgs e) 
        { 
            System.Web.SiteMapNode sm = e.Item.DataItem as SiteMapNode; 
             
            if ((sm.ChildNodes.Count > 0) && (sm.ParentNode.Key == sm.RootNode.Key)) 
            { 
                e.Item.ImageUrl = "arrow-down.png"
                e.Item.ExpandedImageUrl = "arrow-up.png"
                e.Item.ImagePosition = RadPanelItemImagePosition.Right; 
            } 
        } 

    CSS is back to the same as the sample in the KB
    /* <expand arrows> */ 
    .RadPanelBar_ECPanelBar .rpExpandable .rpText, 
    .RadPanelBar_ECPanelBar .rpExpanded .rpText 
        background-colortransparent
        /*background-image: url('PanelBar/Expandable.png');*/ 
     
    /* </expand arrows> */ 

    and here is the markup for the PanelBar
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LeftNav.ascx.cs" Inherits="usercontrols_LeftNav" compilationMode="Always" %> 
    <%@ Register assembly="Telerik.Web.UI, Version=2009.1.311.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4"  
            namespace="Telerik.Web.UI" tagprefix="telerik" %> 
             
    <script type="text/javascript">      
    function onClicking(sender, eventArgs)      
    {      
        var target = eventArgs.get_domEvent().target;  
        var item = eventArgs.get_item();  
        if (target == eventArgs.get_item().get_imageElement())  
        {  
            if (item.get_expanded())  
                item.collapse();  
            else  
                item.expand();  
              
            eventArgs.set_cancel(true);  
        }  
    }      
    </script>  
     
    <telerik:RadAjaxManagerProxy runat="server" ID="rampChild" > 
    </telerik:RadAjaxManagerProxy> 
    <telerik:RadPanelBar runat="server" ID="rpbVertNav" PersistStateInCookie="true"  
         Skin="ECPanelBar"  
        ExpandMode="SingleExpandedItem" EnableEmbeddedSkins="false" 
        OnClientItemClicking="onClicking" onitemdatabound="rpbVertNav_ItemDataBound"  
        MaxDataBindDepth="2"
    </telerik:RadPanelBar> 


    Thanks again for the amazing set of controls. I hope this will helpout someone else.

    Chris

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeremy
    Jeremy avatar
    11 posts
    Member since:
    Nov 2009

    Posted 02 Feb 2010 Link to this post

    I am attempting to utilize the above methodology, but I've ran into the following issue.  I'm doing something wrong, and it's probably obvious....

    upon call of the javascript function, I get the alert("Got Here"), but I never get a match(false) on the next statement, hence I never get an expand or a collapse.... and NEVER get the second 'false' or 'true' can someone give me some insight to what I'm doing wrong??

    Below are the definitions:

    Control Definition:

     

    <telerik:RadPanelBar ID="RadPanelBar2" runat="server" Skin="Web20" ExpandMode="SingleExpandedItem" OnClientItemClicking="onClicking">  
     
    </telerik:RadPanelBar> 
     


    Fill Function:

     

        protected void FillContextualPanelBar2(SiteMapNode siteMapNode)  
        {  
            RadPanelItem panelItem = new RadPanelItem();  
            panelItem.Text = siteMapNode.Title.ToString();  
            panelItem.NavigateUrl = siteMapNode.Url.ToString();  
            RadPanelBar2.Items.Add(panelItem);  
            foreach (SiteMapNode currNode in siteMapNode.ChildNodes)  
            {  
                RadPanelItem panelItem2 = new RadPanelItem();  
                panelItem2.Text = currNode.Title;  
                panelItem2.NavigateUrl = currNode.Url;  
                foreach (SiteMapNode currNodeSubNode in currNode.ChildNodes)  
                {  
                    RadPanelItem panelItem3 = new RadPanelItem();  
                    panelItem3.Text = currNodeSubNode.Title;  
                    panelItem3.NavigateUrl = currNodeSubNode.Url;  
                    panelItem2.Items.Add(panelItem3);  
                    panelItem2.Expanded = false;  
                }  
                RadPanelBar2.Items.Add(panelItem2);  
            }  
        } 

    Page_Load Function

            RadPanelBar2.Items.Clear();  
            FillContextualPanelBar2(SiteMap.Provider.CurrentNode); 

    JavaScript Function: (from previous example)
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
        <script type="text/javascript">  
            function onClicking(sender, eventArgs) {  
                alert("Got Here");  
                var target = eventArgs.get_domEvent().target;  
                var item = eventArgs.get_item();  
                if (target == eventArgs.get_item().get_imageElement()) {  
                    alert("true");  
                }  
                else {  
                    alert("false");  
                }  
                if (target == eventArgs.get_item().get_imageElement()) {  
                    if (item.get_expanded()) {  
                        item.collapse();  
                        alert("true");  
                    }  
                    else {  
                        item.expand();  
                        alert("false");  
                    }  
                    eventArgs.set_cancel(true);  
                }  
            }         
        </script>    
        </telerik:RadScriptBlock> 



     

  5. Chris
    Chris avatar
    58 posts
    Member since:
    Jun 2012

    Posted 03 Feb 2010 Link to this post

    Hi Ray,
                the problem I faced ws that there ws no image element being added to the panelbar item so the js would fail everytime. Are you adding the image elements. If you look at my solution I had to manually add in the databound event. I guess you could add in your FillContextualPanelBar2function?

    Hope this helps

    Chris
  6. Jeremy
    Jeremy avatar
    11 posts
    Member since:
    Nov 2009

    Posted 03 Feb 2010 Link to this post

    As to the images, I used them, and then removed them, I got that part working.  My issue is the javascript code.  Why would i ALWAYS get a false with the following code:

          function onClicking(sender, eventArgs) {  
                alert("Got Here");  
                var target = eventArgs.get_domEvent().target;  
                var item = eventArgs.get_item();  
                if (target == eventArgs.get_item().get_imageElement()) {  
                    alert("true");  
                }  
                else {  
                    alert("false");  
                }  
           } 

    I always get a "Got Here", showing me that the onclick event is firing, and ALWAYS a false with it.
    I need a true on the if statement to get to the expand and collapse.   I'm just trying to understand what might cause this breakdown. 

    The main reason I'm asking in this thread is because I found the code here ;).   Thanks for providing.
  7. Chris
    Chris avatar
    58 posts
    Member since:
    Jun 2012

    Posted 03 Feb 2010 Link to this post

    Hi Ray,
    unfortunately I am not a javascript guru (I wish!!) I seem to remember stumbling around a lot whilst trying to find out why things were not working. But my best guess at this point is that either target or  get_ImageElement returns undefined or just fails. I would suggest using something like FireBug for Firefox to step through the js and see what the flow is and what the values are as you step through. I think this is how I found the solution to my original problem.

    Sorry if this is not much more help, I'll have a better think on it and see if I can come up with any better ideas.

    Chris
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017