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
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" />
<span id="head_caption">A Company Business</span>
<div id="head_main_menu"><Access:MainMenu ID="MainMenu" runat="server" /></div>
And heres the codebehind :
public partial class Header : UserControlBase
protected void Page_Load(object sender, EventArgs e)
I really don't see anything obvious. Can anyone advise?
You are calling the Page_Load handler. You probably want to call the method.
It should be:
protected override void OnLoad(EventArgs 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
Also when using the method override everywhere in your code you can set AutoEventWireup="false" in your templates.
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 :)