ASP.NET Postback Problems



Background
First, I hope everyone knows that the form element in HTML is not a presentation tag but a functionality tag. I had to spell that out just so we are all clear. I've found that many web developers, me inclusive, often find ourselves entangled in usage of multiple redundant form elements on a page. Rather than clean out this clog, we simply leave it because "it after-all causes no one harm". I was soon to to learn otherwise ...

I was redesigning the interface for a legacy ASP.NET 3.5 webforms application (only God knows how we survived the ages when this technology was the de-facto. I so much hate the tight coupling between then presentation and logic layers). In order to jump-start the work, I quickly pasted the HTML from a previous project into the master page and updated the CSS and JavaScript references, then I copied the form tag including all the Content Placeholders from the old master page into the content area. After this, I noticed I now had two form tags, but since only one had the runat="server" attribute, I simply left it "it after-all causes no one harm".

Issue
I had gone far in my work before I observed that my forms were not posting back. It initially started with a Dropdownlist that would not Auto-Postback no matter how well I set the autopostback property. I was in a fix! What was the problem? What had I done wrong?

Solution
As pointed out earlier, I traced the problem to the presence of two form tags on the same HTML page. I removed the one without runat="server" and the application was up and running again. Now I've learnt that the presence of redundant form tags could cause harm.

Comments

Popular posts from this blog

Resize or Crop Image before Upload Using HTML5 File API

Get Creative With Data Tables: Row Click Events

Exception from HRESULT: 0x80131040