November Happy Hour will be moved to Thursday December 5th.

NullReferenceException on SubMenu.PageLink = Menulist.OpenTopPage

Vote:
 

Hi,

I recieve a NullreferenceException on the following line of code:

SubMenu.PageLink = MenuList.OpenTopPage;

when trying to create an EPiServer:PageTree menu control.

My complete code for the SubMenu.ascx:

public partial class LeftMenu : EPiServer.UserControlBase { //Variable private MenuList _menulist; //Property public MenuList Menulist { get { return _menulist; } set { _menulist = value; } } protected override void OnLoad(System.EventArgs e) { base.OnLoad(e); SubMenu.PageLink = Menulist.OpenTopPage; SubMenu.DataBind(); } }

Any ideas why? I'm new to EPi so pelase bear with me ;-)

Thanks for your answers!

 

 

#29855
May 19, 2009 12:00
Vote:
 

Hi,

I think it might be because you are setting the PageLink property too late on the Page_Load event, it should be on the Page_Init event.

Take a look at the example and associated paragraphs about this issue on the following page:

http://sdk.episerver.com/library/cms5/html/P_EPiServer_Web_WebControls_PageControlBase_PageLink.htm

All the best...

#29864
May 19, 2009 14:29
Vote:
 

Hi,

Strange?

I see what you mean. But according to the "Getting Started" demo from EPi World ("Developing a submenu EPiServer:PageTree") it's said to pu the PageLink property in the OnLoad event?

Thanks!

#29865
May 19, 2009 14:59
Vote:
 
public partial class LeftMenu : EPiServer.UserControlBase { //Variable private MenuList _menulist; //Property public MenuList Menulist { get { return _menulist; } set { _menulist = value; } } private void Page_Init(object sender, System.EventArgs e) { SubMenu.PageLink = EPiServer.Core.PageReference.StartPage; } private void Page_Load(object sender, System.EventArgs e) { base.OnLoad(e); SubMenu.DataBind(); } private void InitializeComponent(object sender, System.EventArgs e) { this.Load += new System.EventHandler(this.Page_Load); this.Init += new System.EventHandler(this.Page_Init); } }
Still not working :-)
#29866
May 19, 2009 15:00
Vote:
 

Hi,

 I have coded the following example and it seems to work - you should be able to extend it / shorten it in a way which will work for your solution.  Noting that I have worked with the PageTree in the .ascx file, due to the ease with which the underlying templates can be coded.  I have then attached the PageLink value in the code behind .ascx.cs file. (It seemed to work with both the Page_Load event and Page_Init event).

Hope it helps...

 -- To be copied into the .ascx file (inherits value at the top needs changing to match what's in your solution) --

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LeftMenu.ascx.cs" Inherits="Templates.Units.LeftMenu" %>

<EPiServer:PageTree EvaluateHasChildren="true" ID="SubMenu" runat="server">

    <HeaderTemplate>
        <div id="SubMenuHeader">
            <p>Left Menu</p>
            <EPiServer:Property PropertyName="PageLink" ID="SubMenuPropPageLink1" runat="server" />
        </div>
        <div id="SubMenu">
    </HeaderTemplate>

    <IndentTemplate>
        <ul>
    </IndentTemplate>
   
    <ItemHeaderTemplate>
        <li>
    </ItemHeaderTemplate>
   
    <ItemTemplate>
        <EPiServer:Property PropertyName="PageLink" ID="SubMenuPropPageLink2" runat="server" />
        <asp:PlaceHolder ID="SubMenuPlaceHolderCtrl1" runat="server" Visible="<%# Container.HasChildren %>">[+]</asp:PlaceHolder>
    </ItemTemplate>
   
    <ExpandedItemTemplate>
        <EPiServer:Property PropertyName="PageLink" ID="SubMenuPropPageLink3" runat="server" /> [-]
    </ExpandedItemTemplate>

    <SelectedItemTemplate>
        <EPiServer:Property PropertyName="PageLink" ID="SubMenuPropPageLink4" runat="server" />
        <asp:PlaceHolder ID="SubMenuPlaceHolderCtrl2" runat="server" Visible="<%# Container.HasChildren %>">[-]</asp:PlaceHolder>
    </SelectedItemTemplate>
   
    <TopTemplate>
        <EPiServer:Property PropertyName="PageLink" ID="SubMenuPropPageLink4" runat="server" />
        <asp:PlaceHolder ID="SubMenuPlaceHolderCtrl1" runat="server" Visible="<%# Container.HasChildren %>">[+]</asp:PlaceHolder>
    </TopTemplate>

    <SelectedTopTemplate>
        <EPiServer:Property PropertyName="PageLink" ID="SubMenuPropPageLink5" runat="server" />
        <asp:PlaceHolder ID="SubMenuPlaceHolderCtrl1" runat="server" Visible="<%# Container.HasChildren %>">[-]</asp:PlaceHolder>
    </SelectedTopTemplate>

    <ExpandedTopTemplate>
        <EPiServer:Property PropertyName="PageLink" ID="SubMenuPropPageLink6" runat="server" />
    </ExpandedTopTemplate>
   
    <ItemFooterTemplate>
        </li>
    </ItemFooterTemplate>
   
    <UnindentTemplate>
        </ul>
    </UnindentTemplate>

    <FooterTemplate>
        </div>
    </FooterTemplate>
</EPiServer:PageTree>

-- To be copied into the .ascx.cs file (noting that the events are attached automatically through AutoEventWireup being set to true at the top of the .ascx code) --

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Web.WebControls;

namespace KnowlegdeWebNew.Templates.Units
{
    public partial class LeftMenu : EPiServer.UserControlBase
    {
        private void Page_Load(object sender, System.EventArgs e)
        {
            SubMenu.PageLink = EPiServer.Core.PageReference.StartPage;
        }
    }
}

 

#29870
May 19, 2009 16:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.