Any way to remove all Page.Load event handlers?

Discussion in 'ASP .Net' started by Matthew Burnside, Apr 25, 2004.

  1. 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!
    Matthew Burnside, Apr 25, 2004
    #1
    1. Advertising

  2. 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
    "Matthew Burnside" <> wrote in message
    news:FkWic.1739$...
    > 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!
    >
    >
    Martin Dechev, Apr 26, 2004
    #2
    1. Advertising

  3. 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.

    "Martin Dechev" <> wrote in message
    news:O%...
    > 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
    > "Matthew Burnside" <> wrote in

    message
    > news:FkWic.1739$...
    > > 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!
    > >
    > >

    >
    Matthew Burnside, Apr 26, 2004
    #3
  4. Alternatively, you can response some html and call Response.End() - it will
    interrupt the code execution.

    Greetings
    Martin
    "Matthew Burnside" <> wrote in message
    news:zc7jc.2084$...
    > 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.
    >
    > "Martin Dechev" <> wrote in message
    > news:O%...
    > > 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
    > > "Matthew Burnside" <> wrote in

    > message
    > > news:FkWic.1739$...
    > > > 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!
    > > >
    > > >

    > >

    >
    >
    Martin Dechev, Apr 26, 2004
    #4
  5. Don't know why I didn't think of that; I'll see how it works within our
    framework. Thanks.

    "Martin Dechev" <> wrote in message
    news:...
    > Alternatively, you can response some html and call Response.End() - it

    will
    > interrupt the code execution.
    >
    > Greetings
    > Martin
    > "Matthew Burnside" <> wrote in

    message
    > news:zc7jc.2084$...
    > > 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.
    > >
    > > "Martin Dechev" <> wrote in message
    > > news:O%...
    > > > 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
    > > > "Matthew Burnside" <> wrote in

    > > message
    > > > news:FkWic.1739$...
    > > > > 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!
    > > > >
    > > > >
    > > >

    > >
    > >

    >
    Matthew Burnside, Apr 27, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dood
    Replies:
    1
    Views:
    617
  2. Matcon
    Replies:
    3
    Views:
    21,573
    Matcon
    May 28, 2008
  3. Andy Baldwin

    Event handlers called twice, or not at all

    Andy Baldwin, Oct 14, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    198
    vbMental
    Oct 29, 2004
  4. Andy Baldwin

    Event handlers called twice, or not at all

    Andy Baldwin, Oct 14, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    287
    vbMental
    Oct 29, 2004
  5. niks
    Replies:
    2
    Views:
    69
    Randy Webb
    Aug 11, 2006
Loading...

Share This Page