The methods we have learned to separate Code into different files mainly include:
Assembly.dll, <inherits src>.cs, <script src>.cs, user control.ascx, include, ()
Assembly.dll: This is the most advanced method, which refers to a DLL (assembly) file compiled into IL.
<inherits src>.cs: In this way, 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 separate the <script runat="server"> part into a new file.
User control.ascx: Introduce a piece of code as a control.
include: This is today's topic, please see below for details.
(): It can only be used to introduce a piece of "pure client code (DHTML)" with the extension at will.
Experimental project description:
I think nothing is more telling than a UI, so what page is this?
This is a typical "up, middle, and bottom" structure of web pages. In practice: the "header/footer" may be unchanged, while the middle may be changing.
So in practice, if we use the "include method", we need to separate out the three parts and make a single file.
After that, you can use a "main file" to include three of them separately.
And 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 1 document:】
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)/--><script runat=server>
void click1 (object a,EventArgs b)
{ =;
=;}
</script>
<h1>The Softzz's New page</h1>
<p>2004-11-15</p>
Name:<asp:textbox runat="server"/>
Pass:<asp:textbox runat="server"
textmode="password"/>
<asp:button runat="server"
Text="ClickMe" OnClick="click1"/>
<HR width="80%" SIZE="1">
【Part 1 document:】
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)/--><script runat=server>
void click2 (object a,EventArgs b)
{ =;
=;
}
</script>
<HR width="80%" SIZE="1">
Name:<asp:textbox runat="server"/>
Pass:<asp:textbox runat="server"
textmode="password"/>
<asp:button runat="server"
Text="ClickMe" OnClick="click2"/>
<h5><%= () %></h5>
<b><p>CopyRight: SoftZZ</p></b>
【Main file:】
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)/--><%@ Page Language=C# %>
<center>
<form runat=server>
<!-- #include file="" -->
<br/>
<p>This is a new test 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="" -->
</form>
</center>
Key technologies·Records:
What else can the above example illustrate?
l include can finally spell several files into one file, and each page of the element is just a fragment of the final page that is finally spelled.
l The spelled page and the final page are all code containers, not HTML text.
l When paging pages, they are in order.
l When the code in these files is spelled, it is just ordinary text. When it is finally spelled, it will be checked/compiled/reported/displayed...
l Another file can be included multiple times in one file. But the premise is that the "declaration/definition" (identifier) part cannot be repeated (renamed).
l If there is always a control for "runat=server" in each file, be sure to pay attention to the beginning/end position of <form runat="server">.
l There can only be one <form runat="server"> in a page, and even if the form id can be set, there cannot be multiple.
l <script runat="server"> may appear multiple times in a page, and they will run before the "final page" is displayed.
Also, its running has nothing to do with the page order, it is a "code declaration block", and its elements will only be run after being called.
l We can put <script runat="server"> anywhere on the page, including <form runat="server">.
l Use include method to refer to the file, and the extension can be at will.