. aspx file: (page) write the page code. The page design code is stored. Just put the code for each control, and the processing code is typically placed in a. cs file.
. aspx.cs File: (Code-behind page) write class code. The program code is stored. Typically, you store queries related to database connections and databases. Update. Delete actions, as well as actions that occur after each button click.
. aspx.designer.cs file: Write the page design code. Typically, the configuration information for a control in a page control is to register a control page. This is a code file generated by the form designer that performs the initial execution of a control on a form
<%@ page language= "C #" autoeventwireup= "true" codebehind= "Login.aspx.cs" inherits= "Sczl. Web.Admin.login "%>
The codebehind is used to bind the. aspx.cs file, and inherits is used to bind the. designer file.
The relationship between ASPX and Aspx.cs:
In VS, a lot of friends ask about the relationship between ASPX and Aspx.cs files in a Web site project, which is now summed up as follows:
You can divide the aspx file into three parts:
l have tags for run= "Server" property
L <%%>
L Standard HTML tags
Then count the Aspx.cs, total is four, we respectively say their relationship.
(Figure I)
Let's take a look at the example above.
We create a new website with the following page:
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:button id= "But_yes" runat= "Server" text= "button"/>
<% int i = 10;
THIS.K = i;
%>
</div>
</form>
</body>
The following reference code is as follows:
Using System;
Using System.Configuration;
Using System.Data;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
public partial class _default:system.web.ui.page
{
int j = 10; Private members
protected int k=100; Protect members
protected void Page_Load (object sender, EventArgs e)
{
But_yes.text = "OK";
}
}
Let's examine this example.
First, we're going to publish this and we'll see that the published file looks like this:
(Figure II)
(Figure III)
We mainly look at Default.aspx and this DLL in the bin, and now we use the reflexive tool Red Gate's. NET Reflector to view this DLL file, and found in this file, there is only one class _defaule, such as:
(Figure IV)
Well, we've got all the knowledge ready, and then we're going to analyze figure one.
According to Tuyi, when compiled into a DLL, this _default class should have a label that includes the run= "server" attribute in the Aspx.cs file and in Aspx, which, of course, becomes a field in the class and a field of the control type. As we can see in Figure Four, the Form1 form and But_yes buttons in J,k and aspx in Aspx.cs can be seen, but I cannot be seen in <%%>. How do the tags for run= "server" properties in Aspx.cs and ASPX compile in a class? Reason in Aspx.cs, class _default before the key partial credit, we all know, this is a partial class keyword, that is, you can divide a class into two pieces to write, or to two files to write, Aspx.cs is part of the other part? Another part is the use of the run= "Server" property in Aspx, which becomes a field of the _default class, so we can access these standards in Aspx.cs.
We'll look at figure one again, when a request arrives at the server, the server will generate a class in ASPX <%%>, and this class inherits the _default class, so that the code in <%%> can access the Aspx.cs _ Non-private variables in default, that is, we do not have access to J in the _default class, but can be visited to K in the class.
Finally, _default's subclasses and HTML code, in collaboration with IIS and the CLR, generate a paging file to send to the client.
As we can see, aspx.cs files and server-side controls generate a class,<%%> generates a class, which is generated at run time, it inherits the previous class, and finally the HTML-generated paging file in the ASPX file is sent to the customer.
(The above is tested by vs2008)
aspx file, aspx.cs file, Aspx.designer.cs file