Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permanently disable AutoEventWireup

Tags:

asp.net

I'm working on a project where performance is really important and i would like to disable AutoEventWireup permanently. The problem is in the fact that the page and control directives override the settings from web.config. Since there will be many collaborators on this project it will be impossible to expect everyone to disable it when creating new pages and controls (and it is true by default). Is it possible to somehow enforce this rule?

I hoped to solve this in a similar way as I did with the ViewState - setting the EnableViewState to false programmatically in the base page that all new pages inherit. But it seems there is no equivalent for AutoEventWireup.

like image 752
loodakrawa Avatar asked Feb 18 '12 13:02

loodakrawa


1 Answers

Override 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;
        }
    }
}
like image 188
Adrian Iftode Avatar answered Oct 07 '22 18:10

Adrian Iftode