When using VS2005 for a WebForm project, we found that many aspx pages are loaded twice when page_load () is loaded, and two identical results are output on the Page, it turns out that the AutoEventWireup attribute is a ghost:
<% @ Page language = "c #" Codebehind = "Result. aspx. cs" AutoEventWireup = "true" Inherits = "test. Result" %>
Solution:
<% @ Page language = "c #" Codebehind = "Result. aspx. cs" AutoEventWireup = "false" Inherits = "test. Result" %>
Cause analysis:
If the AutoEventWireup attribute of the Page command is set to true (or if this attribute is missing because it is set to true by default), the Page framework automatically calls the Page events, namely the Page_Init and Page_Load methods. In this case, no explicit Handles clause or delegation is required.
The disadvantage of the AutoEventWireup attribute is that it requires the page event handler to have a specific and predictable name. This limits your flexibility when naming event handlers. Therefore, in Visual Studio, the AutoEventWireup attribute is set to false by default. The designer generates explicit code used to bind page events to methods.
If AutoEventWireup is set to true, Visual Studio generates the code used to bind the event, and the page framework automatically calls the event based on the event name. This may cause the same event code to be called twice when the page is running. Therefore, when operating in Visual Studio, set AutoEventWireup to false whenever possible.
For more information about AutoEventWireup, see Microsoft MSDN