A bug in ASP.NET has returned from the dead to haunt me today. I sat with one of my colleagues for over an hour to try and work out the issue to no avail. The problem was that the first Save worked fine - but I kept getting Optimistic Concurrency data errors when I saved the record for the second time (never the first). The big problem with ASP.NET bugs is that you tend to look in your code for the problem - that single attribute that shouldn't be there, the new code in our custom ObjectContainer data source or translation layer, that line of code that nullifies the value, that AJAX control not set up correctly. But there was none. After stepping through the code line by line, removing any Telerik Ajax Managers and Postback Panels -and anything remotely suspicious at - the problem was still there. After a bit more Divide and Konquering (DK for short) with CTL+E, CTL+C (the VS Shortcut for commenting out code), I finally found my old nemesis of the single empty image tag (which still exists in ASP.NET 3.5).
An example of this bug is detailed here:
It is also detailed here:
The issue occurs if you have any image tags rendered by your controls which have an empty source. As soon as the browser hits that <img src=""/> tag it does a refresh of the page. The main problem with this double postback is that the second run is NOT a postback - the Page.IsPostBack property is false - but I still have all my viewstate values. This issue is incredibly frustrating as the natural inclination is to look at controls causing partial postbacks - but you'd be looking in the wrong place. I had this issue in IE 6,7 and Firefox 2.
When I have some spare time, I'll look into how the problem occurs with Lutz Roeder's handy Reflector and find out who to tell to fix this reocurring issue :o)
To stop the double post-backs, just make sure all your ASP.NET controls (Image Buttons, Image Columns in grids, normal Images), all have a src attribute filled in - or otherwise, make them invisible. Otherwise, you will have phantom postbacks coming to haunt you when you least need it!