Autotmate Page_load events

G

Guest

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

Scott Allen

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

Guest

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

Scott Allen

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?
 
G

Guest

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

Scott Allen

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top