【问题标题】:ASP C# repeat code for every page_Load instance每个 page_Load 实例的 ASP C# 重复代码
【发布时间】:2017-08-09 08:19:06
【问题描述】:

如何在不重复代码的情况下为System.Web.UI.Page 的每个实例向Page_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_Load 事件运行第一个 sn-p 而不为每个网络表单重复代码?

【问题讨论】:

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

标签: c# asp.net oop


【解决方案1】:
 MasterPage.cs
 -----------------
 protected void Page_Load(object sender, EventArgs e)
 {
      Debug.WriteLine("hello");
 }

【讨论】:

  • 谢谢。比我想象的要简单!
猜你喜欢
  • 1970-01-01
  • 2014-12-07
  • 2013-04-26
  • 2021-10-05
  • 2011-12-09
  • 2012-12-27
  • 2021-02-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多