如果我们编写多个C#,C#如何执行Page_Load?

时间:2012-09-26 06:14:18

标签: pageload

如果我在aspx.cs页面中有以下代码:

    protected void page_Load(object sender, EventArgs e)  
    {

    }
    protected void PAGE_LOAD(object sender, EventArgs e) 
    {

    }
    protected void PaGe_LoAD(object sender, EventArgs e)
    {

    }

C#允许我在同一个地方创建这些方法,因为区分大小写这些可区分 ...但编译器如何决定执行哪一个代替其真正的Page_Load? ?
谢谢!!

1 个答案:

答案 0 :(得分:0)

网站配置中的一个属性是AutoEventWireup。
http://msdn.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup.aspx
事件签名在运行时连接,而不是在编译时。所以,它不是编译魔术。

执行一段代码以确定要为哪个事件调用哪个委托。该代码似乎不区分大小写。

有关上述内容的更深入解释,请查看http://odetocode.com/Blogs/scott/archive/2006/02/17/inside-autoeventwireup.aspx信息可能已过时,但我不认为它已过时。

您可以采用的方法确定准确的代码是http://aspnetresources.com/articles/event_handlers_in_global_asax,它为global.asax中的事件处理程序回答相同的问题。

获得反射并愉快地挖掘。