Asp. Use of include in net

Source: Internet
Author: User
Tags final
Asp.net|include Introduction:

We have learned the code to separate the methods of different files, mainly including:

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

Assembly. DLL: This is the most advanced method, referencing a DLL (assembly) file that is compiled to IL.

<inherits Src>.cs: In this way, you can first define a new class that inherits the page class, and then process the class in the Aspx/ascx file.

<script Src>.cs: The <script runat= "Server" > part can be separated into a new file.

User control. ascx: The introduction of a piece of ASP.net code as a control.

Include: This is today's topic, as detailed below.

Response.WriteFile (): He can only be used to introduce a section of "Pure client code (DHTML)", the extension can be arbitrary.




Experiment Project Description:





I think there is nothing more than a UI to illustrate the problem, then what is this page?

This is a typical "up and down" structure of the Web page, in the implementation: "Header/Footer" may be unchanged, and the middle may be changed.

So in practice, if you use the "include" method, we need to separate the three parts to be a single file.

After that, you can use a "master file" to include three files in each.

And today, we are just an experiment, so we designed this:

The middle is a "master file," and then the next two sections are included.

Finally, we will summarize some of the key technologies.



Code implementation:

"Upper part file: Head.aspx"





<script runat=server>

void Click1 (object A,eventargs B)

{Label1. Text=text1. Text;

Label2. Text=text2. Text;}

</script>




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






"Upper part file: End.a"





<script runat=server>

void Click2 (object A,eventargs B)

{Label1. Text=text3. Text;

Label2. Text=text4. Text;

}

</script>




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


<b><p>CopyRight:SoftZZ</p></b>





"Main file: Index.aspx"

<%@ 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/><br/>

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

<br/><br/>

User ' s pass: <b><asp:label Id=label2 runat=server/></b>

<br/><br/>

<!--#include file= "END.A"-->

</form>

</center>



Key Technologies • Accounts:

What else does the example above illustrate?

L include a few files that end up in a single file, and as each page of the element, it's just a fragment of the final page that you spelled.

L The pages that are spelled, the final pages, are asp.net code containers, not HTML text.

L The page is spelled in order.

L These files in the code, when spelled, just plain text, when the final spell, will be checked/compile/error/show ...

L A file can include another file multiple times. However, the premise is that the Declaration/definition (identifier) portion cannot be duplicated (the duplicate name).

L If you end up with a "runat=server" control in each file, be sure to pay attention to the <form runat= the start/end position of the "server" >.

L A page can only have one <form runat= "Server", even if you can set the ID of the form cannot have more than one.

L A page may appear multiple times <script runat= "Server", and it will run before this "final page" display.
Also, it runs independently of the page order, which is a "code declaration block" whose elements are only invoked and then run.

L We can put the <script runat= "Server" >, anywhere on the page, including <form runat= "Server" >.

L Use the Include method to refer to the file, and the extension is optional.











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.