Discussion on the use of ASP.NET's include

  • 2020-05-30 19:48:03
  • OfStack

The methods of separating Code into different files we have learned mainly include:

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

Assembly.dll: this is the most advanced method, which refers to an DLL (assembly) file that has been 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: yes < script runat server = "" > Partial split into a new file.

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

include: that's today's topic. See below.

Response.WriteFile () : it can only be used to introduce a piece of "pure client code (DHTML)" with an optional extension.

Project description:

I don't think there's anything more telling than an UI, so what page is this?

This is a typical "top, middle, bottom" structure for a web page, in the implementation: the "header/footer" may not change, while the middle may change.

So in the implementation, if we use the "include" method, we need to separate three parts, just one file.

After that, you can use a "master file" and bring in three separate files, include.

Today, we only have one experiment, so here's how we designed it:

In the middle is a "main file", after which the upper and lower parts include come in.

Finally, we will summarize some key techniques.

Code implementation:

[head.aspx]


 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</h1>
<p>2004-11-15</p>
Name:<asp:textbox id="text1" runat="server"/>
&nbsp;&nbsp;
Pass:<asp:textbox id="text2" runat="server"
textmode="password"/>
&nbsp;&nbsp;
<asp:button id="button1" runat="server"
Text="ClickMe" OnClick="click1"/>
<HR width="80%" SIZE="1">

[above file: end.a]


 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>
 
<HR width="80%" SIZE="1">
Name:<asp:textbox id="text3" runat="server"/>
&nbsp;&nbsp;
Pass:<asp:textbox id="text4" runat="server"
textmode="password"/>
&nbsp;&nbsp;
<asp:button id="button2" runat="server"
Text="ClickMe" OnClick="click2"/>
<h5><%= DateTime.Now.ToString() %></h5>
<b><p>CopyRight: SoftZZ</p></b>

【 main file: index.aspx】


 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/><br/>
User's Name:&nbsp;<b><asp:label id=label1 runat=server/></b>
<br/><br/>
User's Pass:&nbsp;<b><asp:label id=label2 runat=server/></b>
<br/><br/>
<!-- #include file="end.a" -->
</form>
</center>

Key technologies · description:

What else does the example above say?

l include can combine several files into one file, while each page of elements is just a fragment of the final page.

The parceled and final pages of l are ASP.NET code containers, not HTML text.

When l assembles pages, it does so in order.

The code in these files, l, is only plain text when it is spelled, but when it is finally spelled, it will be checked/compiled/error reported/displayed...

l 1 file can be include 1 file multiple times. Provided, however, that the declaration/definition (identifier) part is not repeated (same name).

l if you end up with a "runat=server" control in each file, be aware of 1 < form runat server = "" > The beginning/end position of.

You can only have one on l page 1 < form runat server = "" > , even if you can set form's id, you can't have more than one.

l 1 May appear multiple times < script runat server = "" > , and it will all run before the "final page" is displayed.
Also, it runs regardless of page order. It is a "code declaration block" whose elements are only called and run.

l we can take < script runat server = "" > They are placed anywhere on the page, including < form runat server = "" > Inside.

l refers to files using the include method, with optional extensions.


Related articles: