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

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

    Read the section called: "Binding Page Events" on the MSDN page titled: "ASP.NET Web Server Control Event Model" (link to the page) There are some useful statements like these:

    One disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, predictable names. This limits your flexibility in how you name event handlers. Another disadvantage is that performance is adversely affected, because ASP.NET searches for methods at run-time. For a Web site with high traffic volumes, the impact on performance could be significant.

    (AutoEventWireup flag turns on such methods like Page_Load)

提交回复
热议问题