怎么樣,看上去很熟悉吧,除了頁首兩句及下面webform中帶runat=server的webcontrol,是不是和普通的html一樣?注意到頁首第一句中的Codebehind="Register.cs"嗎,它指定本頁后面的代碼文件是register.cs,這是asp.net提供的一種機制,它可以將業務邏輯隱藏在與.aspx同名的cs文件中,而運行時先把這個cs文件編譯,這樣不但可以提高運行效率,也使代碼隱藏起來,避免了asp中由于系統漏洞而造成源碼泄漏所造成的問題。那么,這個包含業務邏輯的代碼文件是怎樣的呢?下面是這個文件: namespace bbs { using System; using System.Collections; using System.ComponentModel; using System.Data.SQL; using System.Drawing; using System.Web; using System.Web.sessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using bbs.uctrl ; //using bbs.MyClass ; using MyOwnClass ;
//構造函數 public Register() { Page.Init += new System.EventHandler(Page_Init); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // // Evals true first time browser hits the page // } }
protected void Page_Init(object sender, EventArgs e) { // // CODEGEN: This call is required by the ASP+ Windows Form Designer. // InitializeComponent(); this.myHead1.Position = 2 ; }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler (this.Page_Load); }