Wednesday, February 10, 2010

Dumb mistake

So I made a rookie mistale today and it took me a while to figure it out. I copied a code snippet form one ASP.NET page to another and got myself into trouble. I should know better than to copy and paste code. :)


I had the following code in my page, and I couldn't figure out why I was getting a stack overflow problem.


protected void Page_Load(object sender, EventArgs e)
{
base.OnLoad(e);
//Other code
}


for those who don't quite see the error, the call to the base class causes another call to the Page_Load method in this class and recursion that never ends is ensured.

What I meant to have is:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//Other code
}

It's good to make a dumb mistake once in a while, keeps me from thinking too much of myself. :)

1 comment:

Syd said...

Its all about that ASP.NET page lifecycle and events. Ahh the good ole days back in Boston :)

Syd.