loodakrawa
loodakrawa

Reputation: 1574

Permanently disable AutoEventWireup

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.

Upvotes: 7

Views: 553

Answers (2)

Adrian Iftode
Adrian Iftode

Reputation: 15683

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;
        }
    }
}

Upvotes: 4

IrishChieftain
IrishChieftain

Reputation: 15262

Create your own set of controls for each of the out of the box ones that you want to disable these properties for. Then set the two controls in the inherited versions to readonly.

Upvotes: 0

Related Questions