Autotmate Page_load events

Discussion in 'ASP .Net' started by =?Utf-8?B?QWxleA==?=, Apr 18, 2005.

  1. We have a web site which we need to implement auditing. I've implemented a
    base form which all code behind files inherit from, and I can add the logic
    to it, but that would mean that all existing pages would need to be changed,
    and any future pages would need to also implement the call code.

    Is there a way to automatically call some code when a page_load has been
    invoked without adding code into the Page_Load? Global.asa would be nice, but
    I didn't find it usefull at a page level.
     
    =?Utf-8?B?QWxleA==?=, Apr 18, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?QWxleA==?=

    Scott Allen Guest

    Alex:

    Your base form could also hook up to the Page_Load event, and both the
    derived form and base form could have an event handler.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Mon, 18 Apr 2005 10:25:02 -0700, "Alex"
    <> wrote:

    >We have a web site which we need to implement auditing. I've implemented a
    >base form which all code behind files inherit from, and I can add the logic
    >to it, but that would mean that all existing pages would need to be changed,
    >and any future pages would need to also implement the call code.
    >
    >Is there a way to automatically call some code when a page_load has been
    >invoked without adding code into the Page_Load? Global.asa would be nice, but
    >I didn't find it usefull at a page level.
     
    Scott Allen, Apr 18, 2005
    #2
    1. Advertising

  3. Can you provide with a little more detail on how I can achieve it. Maybe some
    additional keywords I can search on?I don't understand how I can achieve this.

    "Scott Allen" wrote:

    > Alex:
    >
    > Your base form could also hook up to the Page_Load event, and both the
    > derived form and base form could have an event handler.
    >
    > --
    > Scott
    > http://www.OdeToCode.com/blogs/scott/
    >
    > On Mon, 18 Apr 2005 10:25:02 -0700, "Alex"
    > <> wrote:
    >
    > >We have a web site which we need to implement auditing. I've implemented a
    > >base form which all code behind files inherit from, and I can add the logic
    > >to it, but that would mean that all existing pages would need to be changed,
    > >and any future pages would need to also implement the call code.
    > >
    > >Is there a way to automatically call some code when a page_load has been
    > >invoked without adding code into the Page_Load? Global.asa would be nice, but
    > >I didn't find it usefull at a page level.

    >
    >
     
    =?Utf-8?B?QWxleA==?=, Apr 19, 2005
    #3
  4. =?Utf-8?B?QWxleA==?=

    Scott Allen Guest

    Hi Alex:

    I was thinking of pointing you to these articles:

    http://aspnet.4guysfromrolla.com/articles/041305-1.aspx
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/BedrockASPNET.asp

    but it sounds as if you already have a base class that all your
    webforms derive from. In that base class you can hook the Load event
    just like the derived webform does that VS.NET gives you (in C#, you
    would += the Page.Load event). It's ok to have two event handlers
    wired up to the same event.

    Does that make sense?

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/


    On Tue, 19 Apr 2005 11:58:03 -0700, "Alex"
    <> wrote:

    >Can you provide with a little more detail on how I can achieve it. Maybe some
    >additional keywords I can search on?I don't understand how I can achieve this.
    >
    >"Scott Allen" wrote:
    >
    >> Alex:
    >>
    >> Your base form could also hook up to the Page_Load event, and both the
    >> derived form and base form could have an event handler.
    >>
    >> --
    >> Scott
    >> http://www.OdeToCode.com/blogs/scott/
    >>
    >> On Mon, 18 Apr 2005 10:25:02 -0700, "Alex"
    >> <> wrote:
    >>
    >> >We have a web site which we need to implement auditing. I've implemented a
    >> >base form which all code behind files inherit from, and I can add the logic
    >> >to it, but that would mean that all existing pages would need to be changed,
    >> >and any future pages would need to also implement the call code.
    >> >
    >> >Is there a way to automatically call some code when a page_load has been
    >> >invoked without adding code into the Page_Load? Global.asa would be nice, but
    >> >I didn't find it usefull at a page level.

    >>
    >>
     
    Scott Allen, Apr 19, 2005
    #4
  5. Yes, thanks. I added this in InitializeComponent : this.Load += new
    System.EventHandler(base.Page_Load);

    The nice thing about this solution is that it's more scaleable since I can
    keep on adding code in the base form if needed. The only downside is that we
    need to remember to add the line in all of our forms, but I guess that's what
    code reviews are for....
     
    =?Utf-8?B?QWxleA==?=, Apr 20, 2005
    #5
  6. =?Utf-8?B?QWxleA==?=

    Scott Allen Guest

    Ah, yes, but - you can add that line in the base form. Just override
    OnInit and add the event handler for page load. OnInit is called by
    the derived web form in the templated code VS.NET ceates for a new web
    form.

    With that in place you wouldn't need to remember to do anything in the
    derived class.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Wed, 20 Apr 2005 05:15:02 -0700, "Alex"
    <> wrote:

    >Yes, thanks. I added this in InitializeComponent : this.Load += new
    >System.EventHandler(base.Page_Load);
    >
    >The nice thing about this solution is that it's more scaleable since I can
    >keep on adding code in the base form if needed. The only downside is that we
    >need to remember to add the line in all of our forms, but I guess that's what
    >code reviews are for....
     
    Scott Allen, Apr 20, 2005
    #6
    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. John Saunders
    Replies:
    4
    Views:
    372
    Charles Evans
    Aug 22, 2003
  2. bminder
    Replies:
    1
    Views:
    2,214
    nfedin
    Feb 23, 2004
  3. z. f.
    Replies:
    0
    Views:
    590
    z. f.
    Oct 19, 2004
  4. rockdale
    Replies:
    1
    Views:
    693
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 16, 2006
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    425
    Chris
    Aug 30, 2005
Loading...

Share This Page