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.
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:
AutoPostBack is not set to
True for your dropdown list, etc.
ViewState may not be enabled so it does not retain the value.
- Tried putting breakpoints at the start of
SelectedIndexChanged events of the dropdown but it doesn't appear at those breakpoints.
- 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" />
I commented this block and noticed:
- the dropdown value changed on the form
- 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.