2012-01-26 88 views

回答

7

您可以創建一個類讓利說BasePage.cs,在這裏你將有一個虛擬方法的Page_Load:

public class BasePage: System.Web.UI.Page 
{ 
    protected virtual void Page_Load(object sender, EventArgs e) 
    { 
      //Some logic here that you want to execute for all pages 
    } 
} 

然後,在每一個頁面裏要執行的pageLoad的這些代碼,使該網頁從BasePage的繼承和覆蓋pageLoad的方法,像這樣:

文件somePage.aspx.cs做到這一點:

public partial class somePage : BasePage 
{ 
    protected override void Page_Load(object sender, EventArgs e) 
    { 
     base.Page_Load(sender, e); //This line will execute page load from BasePage class 
     //The rest of code you want to execute on this page load 
    } 
} 
相關問題