ASP. NET page inheritance relationship, asp.net page inheritance
Anyone who has used ASP. NET (ASP for short) knows that ASPCode BehindTo show us a development model similar to Winform, also in the Event-triggered way for various request processing. WhereAutoPostback,ViewstateAnd so on, you can start another article. I believe that people who have experienced ASP development will be familiar with it at all. This article focuses on something that is not obvious but is always in touch. YesWhat is the relationship between the front-end page and the backend CS file? Why is the background-defined method that can be directly registered for foreground control events?Many people may have considered this issue and may think it is meaningless. It doesn't matter. It's just a play ~.Note: The ASP control model and the life cycle of a request are complex. If you go into depth, I have a limited level, not to mention whether I can go deep into it to make people addicted, simply proving that the conclusion is true or not makes people throw, so I assume that your level is already good and you will not post additional code here, it will not explain other concepts. Save everyone's time and article space. Sorry!First look at the Code:
public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { }}
We sacrificeAspnet_compilerIt is an asp compilation tool. After compiling the page, you can get several important DLL files. Here, you need to go to MSDN to check their usage, it doesn't matter if you don't have time to do it.
We useILSPY (A. NET decompilation tool)Decompile the two DLL files to obtain:
Open these two DLL files and view their source code. We can see that the aspx page is actually compiled into a class, and the page code is compiled into their corresponding controls. The base class is the Default class in the cs file corresponding to the aspx page, so obviously, the method is inherited from the base class and can be registered. By the way, we can see a lot of interesting underlying technical principles, which will be discussed by everyone.