Understanding the occurrence of
events is helpful for programming. It is a truth for programming ASP.NET pages
as well.
"It is important for you to
understand the page life cycle so that you can write code at the appropriate
life-cycle stage for the effect you intend."
It is quoted from a web page of
Microsoft which emphasizes the importance of trigged events in the life cycle of
ASP.NET pages. This "ASP.NET Page Life Cycle Overview" gives you a overall
concept of events in the life cycle of ASP.NET pages.
Following is quoted form the
same web page. I think it might be important for beginners of ASP.NET, just like
Albert.
"Pages also support automatic
event wire-up, meaning that ASP.NET looks for methods with particular names and
automatically runs those methods when certain events are raised. If the
AutoEventWireup attribute of the @ Page directive is set to true (or if it is
not defined, since by default it is true), page events are automatically bound
to methods that use the naming convention of Page_event, such as Page_Load and
Page_Init."
The first line of the code of
the default ASP.NET page "Default.aspx" which is created automatically after
starting a brand-new ASP.NET Web Site is beneath,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
This line, starts with @Page, has the option parameter "AutoEventWireup" and it's default value is "true". As matter of fact, the value of AutoEventWireup is set to true, it's default value, if it is omitted on purpose. The execution of codes for these event handlers depend on this option (AutoEventWireup.) And furthermore, the names of these event handlers are prefixed with "Page_", such as Page_Load, Page_Init.
沒有留言:
張貼留言