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

前端 未结 8 2064
南笙
南笙 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

    As you can see above, it does mostly come down to personal choice IF that choice is made knowledgeably. The best quick but solid overview I've seen is at http://weblogs.asp.net/infinitiesloop/archive/2008/03/24/onload-vs-page-load-vs-load-event.aspx

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题