views:

392

answers:

4

Why would an event handler work one day, and then stop working the next day without any code changes?

I have run into the problem many times, but always have to play around and somehow the event handler magically works again. Below is an example where this happened to me again today. Do you know a quick way to fix this type of problem?

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">
    Link
</asp:LinkButton>

I set a breakpoint on this method and it never gets hit.

protected void LinkButton1_Click(object sender, EventArgs e)
{
    // snip
}

I have tried cleaning the solution, rebuilding all, etc. Any insight here?

Edit:

Yes, AutoEventWireup is set to true. No other system/development environment changes were made. I'm using .NET 3.5.

+1  A: 

I know you said that no code had changed but you ought to check to make sure that AutoEventWireup is set to true on this page. Also check the web.config to make sure that this attribute is not false for the whole application.

Edit:

The best thing you can do is not to rely on AutoEventWireup as you are here. You really ought to add an explicit event wireup in your OnInit override of the page as this is clearer provides better performance. I am not sure why you are seeing the errors you are seeing but I can almost guarantee that they will go away if you do something like this:

protected override void OnInit(EventArgs e)
{
    this.LinkButton1.Click += new EventHandler(this.LinkButton1_Click);
}
Andrew Hare
Yes, it is set to true.
Aaron
I had just tried that too... still no luck which is very odd.
Aaron
A: 

Does your aspnet_client folder match the .NET framework version installed on the server? If you use a pre-2.0 .NET framework, this version mismatch between the framework and aspnet_client scripts is known to cause problems.

Mehrdad Afshari
Yes, all of this remained constant. Basically it was working on Friday when I left, first thing this morning it stopped working. Nothing has changed.
Aaron
Something must have changed Aaron - it always ends up being the answer to questions like this...
Kieran Benton
+1  A: 

If this is a .NET 1.1 application, check to see that in the OnInit method your event handlers are there. There was a VS.2003 bug that sometimes would strip events. If it's a 2.0 application, I've seen problems with custom controls that the designer complains about interfere with the event generation in pagename.aspx.designer.cs (or .vb). Check your error list and look for any warnings where 'generation of the designer file failed'. This also holds true for .NET 3.5.

bxlewi1
A: 

Kieran was right with his comment... Something actually had changed! Big wow there...

The TFS Check-in alert ended up in my Junk E-mail folder and stupid me didn't do a comparison on the history of the file. The EnableViewState was set to false in the codebehind by a coworker.

As a side note: he did this because it dropped the response size to 10% of what it had been with viewstate enabled. I ended up solving the same problem by using a querystring variable in place of the event handling.

However, thanks for all the ideas. Good thing I didn't waste too much time on this thing.

Aaron