base.OnLoad seems to cause StackOverflowException in all my web user controls

Vote:
 

Hi,

I am creatign a site, using AlloyTech as an example and guide. I note that the first call in the constructor of every WebUserControl is

base.OnLoad(e);

however, whenever I add this simple code line, so as to properly construct my controls, It throws a 'System.StackOverflowException' exception.

StackOverflowException was unhandled

An unhandled exception of type 'System.StackOverflowException' occurred in System.dll

I am a little bit green with EPiServer so I'm not ruling out that I've missed something simple, or that there is a recursion that I'm just not seeing. However the error message gives little clue!

Take my simple PageHeader.ascx for example, pretty much as simple as they come, heres the ascx file

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Header.ascx.cs" Inherits="Access.Templates.Blocks.Header" %>

<%@ Register TagPrefix="Access" TagName="MainMenu" Src="~/Templates/Blocks/MainMenu.ascx" %>

        <div id="header" class="selfClear outerMargin">
            <div id="head_menu" style="color: #898989; font-size: 80%;">SubMenu Goes Here</div>
            <a href="/" title="My Company Homepage">
                <img id="head_logo" src="<%= ResolveUrl("~/Templates/Images/Site/company_logo.jpg") %>" alt="My Company" />
            </a>
            <span id="head_caption">A Company Business</span>
            <div id="head_main_menu"><Access:MainMenu ID="MainMenu" runat="server" /></div>
        </div>

And heres the codebehind :

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 Access.Templates.Blocks
{
    public partial class Header : UserControlBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.OnLoad(e);
            
        }
    }
}

    

I really don't see anything obvious. Can anyone advise?

#55569
Dec 07, 2011 18:14
Vote:
 

You are calling the Page_Load handler. You probably want to call the method.

It should be: 

 

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}

You should know the difference between the event and the method I think. Read this:

http://odetocode.com/Blogs/scott/archive/2005/10/06/page_load-versus-onload.aspx

and this

http://support.microsoft.com/kb/814745

Also when using the method override everywhere in your code you can set AutoEventWireup="false" in your templates.

 

#55570
Edited, Dec 07, 2011 18:23
Vote:
 

Thanks Andreas,

I saw that I was calling the method not the handler in my example, that was my first mistake!

I did however have other templates that were overloading the correct function, and again you are right, it seems I had overlooked the AutoEventWireUp tag in the pages Control tag. This was a complete oversight on my part! It seems when you create an EPiServer Web User Control using the VS Tempaltes it adds AutoEventWireUp="true" as default and I completely missed this.

Thanks for the answer though, most helpful. I have to admin that due to urgencies in project timelines and such I've had to 'dust off' my .NET boots and hit the ground running. And now I do feel kind of rusty!

For this evening I'm going to re-read the links you kindly supply, and further my understanding of the AUtoEventWireUp tag :)

Thanks again.

#55572
Dec 07, 2011 18:51
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.