Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ASP.NET Page Events Not Firing

0.00/5 (No votes)
21 Jun 2013 1  
ASP.NET page events not firing.

Introduction

Sometimes you start pulling your hair knowing enough of ASP.NET, C#, etc. But still you are not able to find the root cause and solution of a simple error. I had this issue for two days with the new ASP.NET web application project. I tried changing many things at the code level, but no luck! Finally, I found something very silly and was able to resolve this issue.

Background

It all started when I designed my Home Page using a Master Page and put in the web parts on it. The basic Header, Footer, and Content area were designed right. Now it was time to put a dropdown list so that I could change the web parts display mode to either Browse, Design, or Catalog. So I put in a dropdown and added list items within the ASPX page and put in the necessary code to change the web part display mode.

As soon as I started running the application, I noticed that when I changed my dropdown value, it posted back to the page and came back to its default value "Browse" although I selected "Design" from the dropdown. I noticed that the dropdown event was not firing.

Using the Code

You tend to think that the events are not fired because:

  1. AutoPostBack is not set to True for your dropdown list, etc.
  2. ViewState may not be enabled so it does not retain the value.
  3. Set AutoEventWireup to true and false one-by-one.
  4. Tried putting breakpoints at the start of Page_Load and SelectedIndexChanged events of the dropdown but it doesn't appear at those breakpoints.
  5. May be issue with web parts, etc. so removed that too, etc.

But, no luck...Yes, I tried all of that, but none of them helped me.

Finally, I noticed something that was completely weird and silly. In my Header control, I had put in the following line:

<form name="search-form" action="#">
    <input type="text" value="Search" name="search" id="txtsearch" />
    <input type="submit" value="GO" id="btnsearch" />
</form>

I commented this block and noticed:

  1. the dropdown value changed on the form
  2. the execution stopped at the breakpoints in the events for debugging.

Finally, Page Events started working!!!

Root cause: It looks like it was re-submitting/posting the form in the header control (in the master page) while reloading the home page. So it did not reach the page events.

Points of Interest

It does not convince me much but I struggled a lot and thought it might be helpful to others.

By the way, this is my first CodeProject post! So, take it easy guys... if I made it too short or too long. And thanks to CodeProject for many great articles by great techies like you that helped me so far.

Happy coding!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here