Using VS2008, C#. When AutoEventWireup is set to true and in a webform I call base.OnLoad(e) like:
protected void Page_Load(object sender, EventArgs e)
{
base.OnLoad(e);
}
The base.OnLoad(e) ends up calling Page_Load (calls itself). This ends up with a stack overflow error. I've been able to solve it by setting AutoEventWireup to false and overriding OnLoad:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
This works as I expected (no stack overflows). But can anyone explain why in the first example base.OnLoad(e) calls the same load event (calls itself) rather than calling the OnLoad event in the base class (System.Web.UI.Page)?
OnLoad doesn't call itself, it calls the Load event. The Page.OnLoad method merely wraps the call to the attached events. You should not call base.OnLoad from a Load event handler or it will result in an infinite loop.