AutoEventWireup和base.OnLoad(五)调用自导致堆栈溢出 [英] AutoEventWireup and base.OnLoad(e) Calling Self resulting in Stack Overflow

查看:246
本文介绍了AutoEventWireup和base.OnLoad(五)调用自导致堆栈溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VS2008,C#。当 AutoEventWireup 设置为true,并在一个WebForm我称之为 base.OnLoad(E)这样的:

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);
}



base.OnLoad(E)结束调用的Page_Load (调用本身)。这与一个堆栈溢出错误结束。我已经能够通过 AutoEventWireup 设置为false并覆盖的OnLoad 来解决这个问题:

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);
}

这工作如我所料(无堆栈溢出)。但是,任何人都可以解释为什么在第一个例子 base.OnLoad(E)调用相同的加载事件(自称),而不是调用的OnLoad 事件的基类( System.Web.UI.Page )?

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不调用本身,它调用Load事件。该Page.OnLoad方法仅仅包装了呼叫连接的事件。你不应该从Load事件处理程序调用base.OnLoad或将导致一个无限循环。

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.

这篇关于AutoEventWireup和base.OnLoad(五)调用自导致堆栈溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆