S
Seraph
Again, I'm rather new here, so if I fail to follow any etiquette,
please forgive me and let me know what I've done wrong, but I think
this might interest quite a few people.
One of my colleaques was endeavoring to create a custom user control to
make things a bit simpler, but she noticed that her Page_Load
eventhandler was firing twice. So after long hours of research and
experimentation, I stumbled upon, imho, is quite the discovery.
If we look at the cookie-cutter code that VS2003 gives us, it reads:
this.Load += new System.EventHandler(this.Page_Load);
As we can see, we are concatenating or appending another EventHandler
onto the this.Load eventhandler which fires on the OnLoad event of the
page, custom control, whatever may use it.
So if I were to have just looked here, I would have realized that there
is a default event handler there, and obviously we are adding another
to it. That default handler, I assumed, is Page_Load.
So when I changed the cookie-cutter'd line to this:
this.Load += new System.EventHandler(this.MyPage_Load);
and also it's respective event handler to:
private void MyPage_Load(object sender, System.EventArgs e)
I expected to get rid of the double firing. And it worked! The Load
event was not fired twice!
So I suspected that the Page_Load event was only fired when there was a
proper event handler created, as in (this.MyPage_Load).
Not SO! I then, just on a hunch, added a function like so:
private void Page_Load() {}
and added a response.Write() to see if it would fire or not.
And it did!! Absolutely nuts. It looks to me like ASP is purposefully
looking for any function that is named "Page_Load" and fires it!!
And furthermore, my colleague did a bit more research, and even after
this line:
this.Load -= new EventHandler(this.Page_Load);
it STILL fired the function!!
Does anyone have any clarification on this, or is this something rather
new? Either way, it's probably one of the dumbest and most annoying
things I've seen microsoft do yet. -_-
--Seraph
please forgive me and let me know what I've done wrong, but I think
this might interest quite a few people.
One of my colleaques was endeavoring to create a custom user control to
make things a bit simpler, but she noticed that her Page_Load
eventhandler was firing twice. So after long hours of research and
experimentation, I stumbled upon, imho, is quite the discovery.
If we look at the cookie-cutter code that VS2003 gives us, it reads:
this.Load += new System.EventHandler(this.Page_Load);
As we can see, we are concatenating or appending another EventHandler
onto the this.Load eventhandler which fires on the OnLoad event of the
page, custom control, whatever may use it.
So if I were to have just looked here, I would have realized that there
is a default event handler there, and obviously we are adding another
to it. That default handler, I assumed, is Page_Load.
So when I changed the cookie-cutter'd line to this:
this.Load += new System.EventHandler(this.MyPage_Load);
and also it's respective event handler to:
private void MyPage_Load(object sender, System.EventArgs e)
I expected to get rid of the double firing. And it worked! The Load
event was not fired twice!
So I suspected that the Page_Load event was only fired when there was a
proper event handler created, as in (this.MyPage_Load).
Not SO! I then, just on a hunch, added a function like so:
private void Page_Load() {}
and added a response.Write() to see if it would fire or not.
And it did!! Absolutely nuts. It looks to me like ASP is purposefully
looking for any function that is named "Page_Load" and fires it!!
And furthermore, my colleague did a bit more research, and even after
this line:
this.Load -= new EventHandler(this.Page_Load);
it STILL fired the function!!
Does anyone have any clarification on this, or is this something rather
new? Either way, it's probably one of the dumbest and most annoying
things I've seen microsoft do yet. -_-
--Seraph