Help, My events are not firing – ASP.NET

My dear friend co-worker authorized my blog to post his valuable finding of today. His own blog link shall not be mentioned as it is ‘work in progress’ and still too ugly and has no dog photos ;-) I will  definitely link it when it is ready, promising good stuff around custom asp.net dev and our favorite SharePoint dev.

Scenario:

You have a website http://site with default document http://site/default.aspx

In default.aspx, you have a button with event handler:

<asp:Button ID=”btnAddNote” Text=”Add Note” runat=”server” OnClick=”OnButtonClick” />

protected void OnButtonClick(object sender, EventArgs args){// some interesting code}

1)      You go to http://site/default.aspx and click button. It works fine!

2)      You go to http://site and click button. Page posts back but NOTHING HAPPENS. No event is fired. You debug, put breakpoint there, but it is never hit.

Conditions:

  • You are running IIS 7.0 or 7.5
  • You are running .NET 4.0
  • You have some httpmodules added in your web.config

Then you may be a victim of a breaking ASP.NET 4.0 change:

http://www.asp.net/whitepapers/aspnet4/breaking-changes#0.1__Toc256770154

Quick solution:

In your code behind, on Page_Load, put:

this.Form.Action = “Default.aspx”;

Leave a Reply