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

前端 未结 8 2154
南笙
南笙 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:24

    Even though you're inheriting from UserControl, I think you should stay away from overriding the protected methods if you don't have to. The Page_Load is there to make it easier for you to add the code that's specific to your UserControl.

    Only override OnLoad if you need absolute control over when(/if) the Load event is fired (which should be rare, IMO).

提交回复
热议问题