2017-08-09 25 views
0

如何在不重复代码的情况下为System.Web.UI.Page的每个实例添加代码到Page_Load()方法?ASP C#为每个页面重复执行代码_负载实例

我想,每次页面加载,该代码

Debug.WriteLine("hello"); 
// other stuff here 
// lots of lines of code 

运行。

所以我有很多的网页,例如

public partial class WebForm1 : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     // don't want to have to repeat all that code above here 

     // stuff that WebForm1 does 
    } 
} 

如何运行每个Page_Load事件的第一个片段,而无需重复代码,每Web窗体?

+0

在母版页加载事件中使用母版页和写入方法 –

回答

1
MasterPage.cs 
----------------- 
protected void Page_Load(object sender, EventArgs e) 
{ 
     Debug.WriteLine("hello"); 
} 
+1

谢谢。比我意识到的更简单! – SEarle1986