使用相同的code隐藏文件多的.aspx页面隐藏文件、页面、code、aspx

2023-09-05 01:27:53 作者:南笙北执

我们正在开发一个网站 CMS 的文件推到我们的生产服务器中。如果 .apsx 页面创建共享隐藏文件相同的code,这将导致一个问题?

We are developing a site inside a CMS that pushed files to our production server. If the .apsx pages created share the same code behind file, will this cause a problem?

推荐答案

为什么你不让这两个页面来自同一个类继承?

Why don't you let both pages inherit from the same class?

public class MyPage : System.Web.UI.Page
{
   // common logic that both pages should have

   protected void Page_Load(object sender, EventArgs e)
   {
   }
}

public partial class PageA : MyPage
{
   // specific logic for page A
}

public partial class PageB : MyPage
{
   // specific logic for page B
}