In fact, I think some people should know the actual application of the. CS class. I used to be ASP. Program Clerk, at that time, using vbs Script Programming, if you want to use other methods (such as public methods), you have to include some functions. ASP, just like running JavaScript, you must first reference other JS functions. Therefore, go to ASP. net, I don't care about the class, and I don't know the differences between static and non-static. It's just like I can call the method after instantiation, and Aspx. all of them are written in CS, which is a brain or a previous programming model. Some people may also have this experience, but we can't keep programming like this. We should be clear about how the method is executed and how we design the class. Create a new ASPX page (I only use ASP here. net web application, instead of website), all generate page. aspx \ page. aspx. desinger. CS and page. aspx. CS, open 2. CS file, we will find that one of them is for us to write the method, the other is to record the control we use (desginer. CS ). In vs2003, desginer. CS does not exist, and all control declarations are in. cs. By default, some Code (As shown below ): # Region Code generated by web Form Designer
Override Protected Void Oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base . Oninit (E );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// The content of this method.
/// </Summary>
Private Void Initializecomponent ()
{
}
# Endregion
We can see that oninit is the initialization event method, which is overwritten by default, because the private method initializecomponent needs to be executed, because each page of the initializecomponent method is different, the reason is different because it is mainly used to subscribe to the events of the control. For example, if the click of button1 has a specific behavior, this will be added here. button1.click + = new eventhandler (button#click); this way, when the button is clicked, The button#click method will be executed, these subscription codes vs are automatically added (although you can manually change them), and 2005 will be hidden (implemented internally ).
As we can imagine, the class execution sequence is oninit-> initializecomponent-> page_load-> your function. Of course there are other event methods. Let's take a look. [Note] This is a frequently used interview question: the lifecycle of ASP. NET! The so-called life cycle, we all know a variable scope, an object from creation to destruction is his life cycle. Therefore, this question is the execution sequence of your pagename page class. After the execution is complete, it will naturally disappear. The newly created pages are inherited from the system. Web. UI. Page class, so it basically depends on the execution sequence of the page class. See official explanation for details: http://msdn.microsoft.com/zh-cn/library/ms178472 (vs.80). aspx, which describes the entire process and related events. In fact, the page class also inherits from the control class, so the page is also a control, so some events in the lifecycle are actually controlled, such as oninit, onload, onprerender, onUnload, ondatabinding, therefore, other controls also support these events. When developing custom controls, you can also operate these events to customize the control features.