Page_Init vs OnInit

后端 未结 6 536
日久生厌
日久生厌 2020-12-08 07:40

Between handling the Page_Init event or overriding the OnInit method of a Page, which one is better to use? Thanks.

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 08:05

    Overriding the base type's method is preferable as a virtual call is simpler and cleaner than creating a delegate attaching an event to a method group.

    Also, relying on AutoEventWireup being set to true means that you are introducing overhead into the parsing of your page code as ASP.NET will have to create any delegates for you at execution-time.

提交回复
热议问题