Problem creating PanelBar dynamically

5 posts, 0 answers
  1. Rob Venable
    Rob Venable avatar
    48 posts
    Member since:
    Dec 2009

    Posted 30 Jan 2010 Link to this post

    Hi,
    I'm trying to create a RadPanelBar dynamically and it doesn't seem to work. This is my code.
    Dim radPanelBarDistributor As New RadPanelBar  
            radPanelBarDistributor.Width = Unit.Pixel(158)  
            radPanelBarDistributor.Skin = "WebBlue" 
            radPanelBarDistributor.ExpandMode = PanelBarExpandMode.SingleExpandedItem  
            radPanelBarDistributor.PersistStateInCookie = True 
            radPanelBarDistributor.Attributes.Add("runat""server")  
     
            Dim rpi As RadPanelItem  
            Dim childItem As RadPanelItem  
            '== My Account  
            rpi = New RadPanelItem  
            rpi.Text = "My Account" 
     
            childItem = New RadPanelItem  
            childItem.Text = "My Profile" 
            childItem.NavigateUrl = "~/Manage/Profile.aspx" 
            rpi.Items.Add(childItem)  
     
            childItem = New RadPanelItem  
            childItem.Text = "AutoShip Options" 
            childItem.NavigateUrl = "~/Manage/AutoShip.aspx" 
            rpi.Items.Add(childItem)  
     
            childItem = New RadPanelItem  
            childItem.Text = "My Orders" 
            childItem.NavigateUrl = "~/Manage/MyOrders.aspx" 
            rpi.Items.Add(childItem)  
            radPanelBarDistributor.Items.Add(rpi)  
            'RadPanelBar1.Items.Add(rpi)  
            '== Only Distributors can see the extended menu  
            If UserInstance.ContactTypeID = CInt(Harmony.Common.Constants.ContactType.Distributor) Then 
                '== Manage  
                rpi = New RadPanelItem  
                rpi.Text = "Manage" 
     
                childItem = New RadPanelItem  
                childItem.Text = "Enroll a Distributor" 
                childItem.NavigateUrl = "~/Manage/Enrollment.aspx" 
                rpi.Items.Add(childItem)  
     
                childItem = New RadPanelItem  
                childItem.Text = "Enroll a Customer" 
                childItem.NavigateUrl = "~/Manage/Enrollment.aspx" 
                rpi.Items.Add(childItem)  
     
                childItem = New RadPanelItem  
                childItem.Text = "Place an Order" 
                childItem.NavigateUrl = "~/Products.aspx" 
                rpi.Items.Add(childItem)  
     
                'RadPanelBar1.Items.Add(rpi)  
                radPanelBarDistributor.Items.Add(rpi)  
     
                '== Prosperity  
                rpi = New RadPanelItem  
                rpi.Text = "Prosperity" 
     
                childItem = New RadPanelItem  
                childItem.Text = "View Trees" 
                childItem.NavigateUrl = "~/Manage/Downline.aspx" 
                rpi.Items.Add(childItem)  
     
                childItem = New RadPanelItem  
                childItem.Text = "Commissions" 
                childItem.NavigateUrl = "~/Manage/Commissions.aspx" 
                rpi.Items.Add(childItem)  
     
                childItem = New RadPanelItem  
                childItem.Text = "Prosperity Card" 
                childItem.NavigateUrl = "~/Manage/ProsperityCard.aspx" 
                rpi.Items.Add(childItem)  
     
                childItem = New RadPanelItem  
                childItem.Text = "Marketing Center" 
                childItem.NavigateUrl = "~/Manage/Marketing.aspx" 
                rpi.Items.Add(childItem)  
     
                'RadPanelBar1.Items.Add(rpi)  
                radPanelBarDistributor.Items.Add(rpi)  
     
            End If 
            pnlDistributorMenu.Controls.Add(radPanelBarDistributor) 

    The menus don't open up and i get the following error: "Microsoft JScript runtime error: 'undefined' is null or not an object" with a Break, Continue, Ignore dialog box.

    Is there anything I'm doing wrong?
  2. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 30 Jan 2010 Link to this post

    Are you making it in Page_Init?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rob Venable
    Rob Venable avatar
    48 posts
    Member since:
    Dec 2009

    Posted 31 Jan 2010 Link to this post

    I tried that as well...but with the same result.
  5. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 31 Jan 2010 Link to this post

    I did a quick test, seems to create fine on my end.  You don't need the runat="server" attribute if you're creating it on the server.

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Telerik.Web.UI; 
     
    public partial class _Default : System.Web.UI.Page  
        protected void Page_Init(object sender, EventArgs e) 
        { 
            this.CreatePanelBar(); 
        } 
     
        private void CreatePanelBar() { 
            RadPanelBar panelBar = new RadPanelBar(); 
     
            RadPanelItem root1 = new RadPanelItem("Root1"); 
            root1.Items.Add(new RadPanelItem("Child1")); 
            root1.Items.Add(new RadPanelItem("Child2")); 
            root1.Items.Add(new RadPanelItem("Child3")); 
     
     
            RadPanelItem root2 = new RadPanelItem("Root2"); 
            root2.Items.Add(new RadPanelItem("Child1")); 
            root2.Items.Add(new RadPanelItem("Child2")); 
            root2.Items.Add(new RadPanelItem("Child3")); 
     
            RadPanelItem root3 = new RadPanelItem("Root3"); 
            root3.Items.Add(new RadPanelItem("Child1")); 
            root3.Items.Add(new RadPanelItem("Child2")); 
            root3.Items.Add(new RadPanelItem("Child3")); 
     
            panelBar.Items.Add(root1); 
            panelBar.Items.Add(root2); 
            panelBar.Items.Add(root3); 
     
            panelPlaceHolder.Controls.Add(panelBar); 
        } 
     


    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> 
     
    <!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></title
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
        <telerik:RadScriptManager ID="scriptMan" runat="server" /> 
        <asp:PlaceHolder ID="panelPlaceHolder" runat="server" /> 
        </div> 
        </form> 
    </body> 
    </html> 
     




  6. Rob Venable
    Rob Venable avatar
    48 posts
    Member since:
    Dec 2009

    Posted 31 Jan 2010 Link to this post

    OK, my mistake. This didn't work either but then I noticed that I had my original menu that I created in Design View was commented out and even though the HTML part was commented out it still created this error. I removed the code and it works. Thanks for your help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017