2012-02-18 110 views
5

我正在處理性能非常重要的項目,我想永久禁用AutoEventWireup。問題在於頁面和控制指令覆蓋了web.config中的設置。由於這個項目上會有很多協作者,所以當創建新的頁面和控件時(默認情況下它是真實的),不可能期望每個人都禁用它。 是否有可能以某種方式執行此規則?永久禁用AutoEventWireup

我希望以類似於我對ViewState的方式來解決此問題 - 在所有新頁面繼承的基頁中以編程方式將EnableViewState設置爲false。但是似乎沒有AutoEventWireup的等價物。

回答

3

覆蓋SupportAutoEvents

public class BasePage : System.Web.UI.Page 
{ 
    public BasePage() 
    { 
     this.Init += (_o, _e) => { 
      this.Load += (o, e) => { 
       Response.Write("in page handler"); 
      }; 
     }; 
    } 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     // this handler is NOT assigned to the Load event 
     Response.Write("assigned by ASP .Net handler");    
    } 
    protected sealed override bool SupportAutoEvents 
    { 
     get 
     { 
      return false; 
     } 
    } 
} 
+0

從文檔:「此屬性支持.NET Framework基礎結構,不適合直接在代碼中使用。」你能解釋你在做什麼嗎? :) – IrishChieftain 2012-02-18 14:36:56

+0

我ILSpy(http://wiki.sharpdevelop.net/ILSpy.ashx)。 – 2012-02-18 14:43:02

+1

優秀!這正是我一直在尋找的。 Thanx – loodakrawa 2012-02-18 15:07:54

0

爲每個要禁用這些屬性的開箱即用的控件創建一組控件。然後將繼承版本中的兩個控件設置爲只讀。