ASP.NET 代码隐藏中的 page_load 和 onLoad 函数有什么区别?
最佳答案
您可能应该阅读 Page Lifecycle Overview了解更多信息。
这一点应该有助于消除差异:
Note that when an event handler is created using the Page_event syntax, the base implementation is implicitly called and therefore you do not need to call it in your method. For example, the base page class's OnLoad method is always called, whether you create a Page_Load method or not. However, if you override the page OnLoad method with the override keyword (Overrides in Visual Basic), you must explicitly call the base method. For example, if you override the OnLoad method on the page, you must call base.Load (MyBase.Load in Visual Basic) in order for the base implementation to be run.
和
Pages also support automatic event wire-up, meaning that ASP.NET looks for methods with particular names and automatically runs those methods when certain events are raised. If the AutoEventWireup attribute of the @ Page directive is set to true, page events are automatically bound to methods that use the naming convention of Page_event, such as Page_Load and Page_Init.
OnLoad 是页面的一部分并且总是被调用。您不需要 Page_Load 方法,它只是事件的可选扩展。
关于c# - page_load 和 onLoad 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3464898/