Saturday, December 18, 2010

Programmatically disable UpdatePanels

In this post I'll show you how to programmatically disable all UpdatePanels in a page. I don't know in which scenario you would want to use this, but I had to use it to hack around an issue with the ReportViewer control. I'll save you the details, really.

To disable all the UpdatePanels, you need to set the EnablePartialRendering property of the ScriptManager to false. You can get a reference to the current ScriptManager by using the GetCurrent() method passing in a reference to the current page.
protected void Page_Init(object sender, EventArgs e) {
ScriptManager.GetCurrent(this.Page).EnablePartialRendering = false;
There is one gotcha: you need to set this property on the Page_Init event, otherwise an InvalidOperationException gets thrown.