ASP.NET提供了两种组织代码的方式,不管是ASP.NET1.X还是ASP.NET2.0都是通用的(1)内置代码分离这是最基本的一种方式,感觉是为了和传统的ASP兼容才提出的。这种方式同样用于介绍ASP.NET知识点,例如建立一个WebCodeSeparated.aspx页面,可能的代码如下WebCodeSeparated.aspx</html><head><script ruant="server"></script></head><body></body></html>(2)页面布局和逻辑代码分离的文件, VS2003就采用的这种思想,例如上面的WebCodeSeparated.aspx可能为WebCodeSeparated.aspx和WebCodeSeparated.aspx.cs为了关联两者关系,可以使用Codebehind和Inherits进行说明 在VS2005里,提供了parital关键字 现在把一个Label控件、一个TextBox控件和一个Button控件托放到WebCodeSeparated.aspx上,最后生成的Source类似如下:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebCodeSeparated.aspx.cs" Inherits="WebCodeSeparated" %>WebCodeSeparated.aspx<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div> </form></body></html> WebCodeSeparated.aspx.cspublic partial class WebCodeSeparated : System.Web.UI.Page 相关文章: