Click here to Skip to main content
15,878,809 members
Articles / Web Development / ASP.NET
Tip/Trick

ASP.NET Page Events Not Firing

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
21 Jun 2013CPOL2 min read 21.9K   3   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:

ASP.NET
<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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
GeneralMy vote of 5 Pin
GregoryW22-Jun-13 0:10
GregoryW22-Jun-13 0:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.