ASP C#为每个页面加载实例重复代码

ASP C#为每个页面加载实例重复代码,c#,asp.net,oop,C#,Asp.net,Oop,如何为System.Web.UI.Page的每个实例向Page\u Load()方法添加代码而不重复代码 我想,每次加载一个页面时 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, Eve

如何为
System.Web.UI.Page
的每个实例向
Page\u Load()
方法添加代码而不重复代码

我想,每次加载一个页面时

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\u Load
事件运行第一个代码段,而不为每个Web表单重复代码?

使用母版页加载事件中的母版页和写入方法谢谢。比我想象的要简单!
 MasterPage.cs
 -----------------
 protected void Page_Load(object sender, EventArgs e)
 {
      Debug.WriteLine("hello");
 }