Any way to remove all Page.Load event handlers?


M

Matthew Burnside

We're creating several different websites all based on a common framework,
including a base page from which all pages inherit. This page is responsible
for rendering the page layout, etc.

I'm implementing a bit of functionality that reads an XML file for scheduled
website downtimes; if there is a current downtime entry, the parent page
removes any and all child controls that have been added by the child page,
and presents a few literal controls explaining the situation.

The problem: load handlers attached by the child page still fire. (As well
they should.) In many cases, these handlers do the sorts of things that
will cause problems during downtimes, such as trying to connect to a
database. I'd like to know if there's a way to programatically remove load
handlers added by the child page from within the parent page.

There are other solutions I can think of, such as doing a redirect to a
notification page, but I'd like to handle it all within the purview of the
parent page if at all possible.

Thanks!
 
Ad

Advertisements

M

Martin Dechev

Hi, Matthew Burnside,

You can set a boolean property in the base class and then just check it in
the child classes' methods. eg:

public class BasePage : Page
{
bool _dontProcess;

protected bool DontProcess
{
get{return _dontProcess;}
}

protected void Page_Load(object s, EventArgs e)
{
if(something){
_dontProcess = true;
HideControls(); // etc......
return;
}
}
}

public class SomePage : BasePage
{
protected void Page_Load(object s, EventArgs e)
{
if(base.DontProcess)
return;
// continue normally
}
protected void SomeButton_Click(object s, EventArgs e)
{
if(base.DontProcess)
return;
// continue normally
}
}

Hope this helps
Martin
 
M

Matthew Burnside

Yeah, I had considered that, but I'm trying to insulate the developers of
the child pages from having to be aware of this, and I'm worried that even
if they know about it they won't apply it consistently.

OTOH, it may be the only way. Thanks for responding.
 
M

Martin Dechev

Alternatively, you can response some html and call Response.End() - it will
interrupt the code execution.

Greetings
Martin
 
Ad

Advertisements

M

Matthew Burnside

Don't know why I didn't think of that; I'll see how it works within our
framework. Thanks.
 

Top