Relationship between aspx and Aspx. CS files: [reprinted]

Source: Internet
Author: User

In vs, many friends asked about the relationship between aspx and Aspx. CS files in a website project, which is summarized as follows:

The aspx file can be divided into three parts:

L labels with the run = "server" attribute

L <%>

L standard HTML Tag

After calculating the Aspx. CS, there are four parts in total. Let's talk about their relationship separately.

 

(Figure 1)

Let's take an example. Let's take a look at the example above.

Create a website on 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">

 

<HTML xmlns = "http://www.w3.org/1999/xhtml">

<Head runat = "server">

<Title> No title page </title>

</Head>

<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>

</Html>

The following parameter 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 member

Protected int K = 100; // protects members

Protected void page_load (Object sender, eventargs E)

{

But_yes.text = "OK ";

}

}

Let's analyze this example.

First, we want to release this file and we will see the published file as shown in:

 

(Figure 2)

 

(Figure 3)

We mainly look at default. this DLL in aspx and bin, now we use the reverse tool red gate's. net reflector to view the DLL file, and found that there is only one class _ defaule in this file, such:

 

(Figure 4)

Well, we have prepared all the knowledge. Next, we will analyze figure 1.

According to Figure 1, after being compiled into a DLL, this _ default class should include Aspx. in the CS file and aspx, there are labels with the run = "server" attribute. Of course, it is a field in the class and it is a field of the control type. We can see in Figure 4 that the form1 form and but_yes buttons in j, k, and aspx in Aspx. CS can be seen, but the I in <%> is not seen. How are the labels of the run = "server" attribute in Aspx. CS and aspx compiled into a class? The cause is Aspx. in CS, we all know the credit for the key partial before class_default. This is a key word of the Division class, which can be written into two classes, it can be written into two files, aspx. CS is a part. What about another part? The other part is to use the run = "server" attribute sign in Aspx. These labels become a field of the _ default class, so we can access these standards in Aspx. CS.

Next, let's look at Figure 1. When a request arrives at the server, the server generates a class in aspx, and this class inherits the class _ default. That is to say, the code in <%> can access Aspx. the non-private variable in _ default in CS, that is, we cannot access J in _ default class, but can access K in this class.

Finally, the _ default subclass and HTML code generate a page file and send it to the client in collaboration with IIS and CLR.

In summary, we can see that Aspx. the CS file and the server-side control generate a class. <%> A class is generated at runtime, which inherits the previous class, finally, combine the HTML in the aspx file to generate a page file and send it to the customer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.