I got a call from a colleague I had done some work for who was having some problems with a some pages I had whipped up for him a few months back. In between then and now, the Web server had died and was rebuilt. After the rebuild, though, some pages submit buttons stopped working altogether. One would go to a page, fill in the form values, and click the Submit button and... nothing would happen. No error. No message on the screen. No sending to a blank page. No postback. Just nothing.
You can imagine how much fun our conversation became when I visited the URL my colleague was having a problem with and... everything worked perfectly for me. I could not repro any of the behavior he was experiencing. After a few confused and frustrating minutes I realized that he was probably using IE and here I was using FireFox, so I switched to IE and was able to repro the problem. This clued me into the source of the problem being the client-side validation used by the page, since this client-side validation was not emitted to “downlevel” browsers like FireFox.
I visited the page and attached the Visual Studio .NET debugger to do script debugging on IE. I found that the problem was in the form statement, where there was:
<form ... onsubmit="if (!ValidatorOnSubmit()) return false;" ...>
Now, if a form's onsubmit event handler returns false it short-circuits the form submission process, and the return statement was executing through the debugger, so that popped out as the problem. But why was it returning false? Shouldn't it not do that? To try to better understand what was going on, I poked through the ValidatorOnSubmit() function, whose code is shown below:
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
return true;
}
The ValidatorCommonOnSubmit() method, I found, was located in WebUIValidation.js. Looking at that function I found the following code:
function ValidatorCommonOnSubmit() {
event.returnValue = !Page_BlockSubmit;
Page_BlockSubmit = false;
}
I am not a JavaScript expert in the least, but this function looked a bit odd. Shouldn't it be returning a value? Perhaps, I reasoned, the event.returnValue was setting the return value of the function. But then why was ValidatorOnSubmit() returning false? I decided to Google “validatoronsubmit returning false” which turned up a single result, a blog entry by Thomas Freudenberg that described the exact same problem and a workaround.
In a nutshell a hotfix for the .NET Framework 1.1 causes this problem, as it has the WebUIValidation.js file and the onsubmit event handler in the form tag out of sync. If you have the ValidatorCommonOnSubmit() function like the one shown above the onsubmit event handler should just have onsubmit="ValidatorOnSubmit();". If, however, you have the onsubmit event handler as shown above (onsubmit="if (!ValidatorOnSubmit()) return false;") then the ValidatorCommonOnSubmit() function should return the value of !Page_BlockSubmit (the value of Page_BlockSubmit before it's set to false).
Basically the hotfix puts the rendered onsubmit out of sync with the WebUIValidation.js file. So if you have installed the hotfix - as my colleague had when rebuilding the Web server - then you will need to update the ValidatorCommonOnSubmit() function in WebUIValidation.js so that it looks something like:
function ValidatorCommonOnSubmit()
{
event.returnValue = !Page_BlockSubmit;
ret_Val = !Page_BlockSubmit;
Page_BlockSubmit = false;
return ret_Val;
}