Introduction to the use of ASP. NET include

Source: Internet
Author: User

The methods for separating Code from different files include:

Assembly. dll, <inherits src>. cs, <script src>. cs, user control. ascx, include, Response. WriteFile ()

Assembly. dll: This is the most advanced method. It references a DLL (assembly) file compiled as IL.

<Inherits src>. cs: using this method, you can first define a new class that inherits the Page class, and then process this class in the ASPX/ASCX file.

<Script src>. cs: You can detach the <script runat = "server"> part from a new file.

User Control. ascx: introduces a piece of ASP. NET code as a control.

Include: this is the topic of today. For details, see.

Response. WriteFile (): it can only be used to introduce a piece of "Pure client code (DHTML)". The extension can be arbitrary.

Lab project description:

I think there is nothing more than a UI, so what is this page?

This is a typical "Top-bottom" structure of the web page. In practice, the "page header/footer" may not change, but the center may change.

In practice, if we use the "include" method, we need to separate the three parts into one file.

You can use a "main file" to include the three files.

Today, we are just an experiment, so we designed it like this:

The middle part is a "main file", and then the upper and lower parts are included.

Finally, we will summarize some key technologies.

 

Code implementation:

[Part of the above file: head. aspx]

Copy codeThe Code is as follows:
Code


Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/--> <script runat = server>

Void click1 (object a, EventArgs B)

{Label1.Text = text1.Text;

Label2.Text = text2.Text ;}

</Script>

 

<H1> The Softzz's New page

<P> 2004-11-15 </p>

Name: <asp: textbox id = "text1" runat = "server"/>

Pass: <asp: textbox id = "text2" runat = "server"

Textmode = "password"/>

<Asp: button id = "button1" runat = "server"

Text = "ClickMe" OnClick = "click1"/>

& Lt; HR width = "80%" SIZE = "1" & gt;

[Part of the above file: end.]

Copy codeThe Code is as follows:
Code


Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/--> <script runat = server>

Void click2 (object a, EventArgs B)

{Label1.Text = text3.Text;

Label2.Text = text4.Text;

}

</Script>

 

& Lt; HR width = "80%" SIZE = "1" & gt;

Name: <asp: textbox id = "text3" runat = "server"/>

Pass: <asp: textbox id = "text4" runat = "server"

Textmode = "password"/>

<Asp: button id = "button2" runat = "server"

Text = "ClickMe" OnClick = "click2"/>

<H5> <% = DateTime. Now. ToString () %>

<B> <p> CopyRight: SoftZZ </p> </B>

[Main file: index. aspx]

Copy codeThe Code is as follows:
Code


Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/--> <% @ Page Language = C # %>

<Center>

<Form runat = server>

<! -- # Include file = "head. aspx" -->

<Br/>

<P> This is a new test page. Please look at the info: </p>

<Br/>

User's Name: <B> <asp: label id = label1 runat = server/> </B>

<Br/>

User's Pass: <B> <asp: label id = label2 runat = server/> </B>

<Br/>

<! -- # Include file = "end. a" -->

</Form>

</Center>

Key Technologies-description:

What else can I explain in the above example?

L include can combine several files into one file. Each page of an element is a part of the final page.

L The spelled pages and final pages are ASP. NET code containers, rather than HTML text.

L in order.

L The code in these files is only common text when it is spelled out. After it is finally assembled, it will be checked/compiled/reported/displayed ......

L one file can include another file multiple times. However, the premise is that the "Declaration/Definition" (identifier) part cannot be duplicated (duplicate ).

L if there is a "runat = server" Control in each file, pay attention to the Start/end position of <form runat = "server">.

L only one <form runat = "server"> can be displayed on a page, and no more than one form id can be set.

L <script runat = "server"> may appear multiple times on one page, and all of them will run before the "final page" is displayed.
In addition, its operation is irrelevant to the page sequence. It is a "code declaration block" and its elements will only run after being called.

L we can place <script runat = "server"> in any part of the page, including <form runat = "server">.

L use the include method to reference files. The extension can be arbitrary.

Related Article

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.