Validators, AJAX UpdatePanels & IIS6 = A nice bug!

The Problem:

On MMT we have an aspx page with nested user controls – a parent user control is permanently displayed whereas the child user control is displayed in certain scenarios. Within the child user control we have two textboxes, dropdown lists and a suite of validators (comprising required field, regex and compare validators) all within an AJAX UpdatePanel.

We were developing a change (simple straight-forward compare validator between the two textboxes to make sure they contain equal values). Everything worked as you would expect during development – where the site is running on the VS 2005 Cassini web server.

However when deploying to our internal UAT box (Windows Server 2003 & IIS6) the compare validator would only fire on a full postback of the page (and not when losing focus from the second textbox as you would expect). I quickly attempted to reproduce the problem on my local box against IIS7 – only to find that it appears to be confined to IIS6 (and previous versions too I assume).

So in summary, the problem is: ASP Net validators do no work as expected when contained in AJAX UpdatePanels – but only on an IIS6 box.

 

The solution:

A quick search on Google revealed that we were not alone with this problem – with one suggestion on an MSDN blog being to download a dll (containing a sample set of validators) and place it the bin directory of our application, update the web.config slightly and hey presto problem solved. However, this didn’t work for us and it didn’t seem appropriate to be using dlls from unknown sources.

So, our solution (which may not be appropriate in all cases) was to restructure the page such that the two textboxes and accompanying validators were outside of all UpdatePanels. This was only possible as there was no real need for the textboxes to be contained within an UpdatePanel (other parts of the child control did have a need however). I appreciate that this won’t be a solution for everyone but this blog entry should highlight the potential problem for readers.