When creating a web control should you override OnLoad or implement Page_Load

前端 未结 8 2156
南笙
南笙 2020-12-19 02:25

When you create a new web user control in visual studio it by default adds the Page_Load event. What is the advantage to using this rather than overriding the base On

8条回答
  •  情书的邮戳
    2020-12-19 03:29

    It's really just a matter of choice. To me it seems weird for an object to attach an event to itself, especially when there is a method you can override.

    I think the ASP.NET team used events because that was the model for Global.asa in ASP, and to lower the bar for developers who don't understand inheritance and overriding virtual methods.

    Overriding the method does require more knowledge about the page lifecycle, but there is nothing "wrong" with it.

提交回复
热议问题