首页 > 编程 > .NET > 正文

浅谈ASP.NET的include的使用方法

2024-07-10 12:46:17
字体:
来源:转载
供稿:网友

我们学过的Code分离到不同文件的方法,主要包括:

程序集.dll、<inherits src>.cs、<script src>.cs、用户控件.ascx、include、Response.WriteFile()

程序集.dll:这是最高级的方法,它引用的是一个被编译为IL的DLL(程序集)文件。

<inherits src>.cs:用这种方法,可以先定义一个继承Page类的新类,再在ASPX/ASCX文件中加工此类。

<script src>.cs:可以把<script runat=”server”>部分分离到一个新文件。

用户控件.ascx:把一段ASP.NET代码作为一个控件引入。

include:这是今天的主题,详见下。

Response.WriteFile():他只能用于引入一段“纯客户端代码(DHTML)”,扩展名可随意。

实验项目描述:

我想没有什么比一个UI更说明问题了,那么这是一个什么页面呢?

这是一个典型的“上中下”结构的网页,在实作中:“页头/页脚”可能是不变的,而中部可能是变化的。

于是在实作中,如果用“include法”我们需要把三个部分离出来,单为一个文件。

之后,可以使用一个“主文件”,分别把它们三个文件include进来。

而今天,我们只是一个实验,所以我们是这样设计的:

中部为一个“主文件”,之后把上下两部分include进来。

最后,我们还会把一些关键技术进行总结。

 

代码实现:

【上部分文件:head.aspx】

代码如下:
代码


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

  

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

textmode="password"/>

  

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

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

<HR width="80%" SIZE="1">

【上部分文件:end.a】

代码如下:
代码


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

  

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

textmode="password"/>

  

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

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

<h5><%= DateTime.Now.ToString() %></h5>

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表