Saturday, March 24, 2012

Derived Validator Controls Bug

Found an obscure bug in the derived validator controls that work with AJAX. I'm toying with a response filter that strips unneeded newlines and tabs from the rendered response, and it worked great until I used the derived validor controls for AJAX; then I received javascript errors.

The problem is a missing ; that works fine unless the \n is stripped out. Easy fix in ValidatorHelper.cs, just add the ; in the function below...

public static void DoValidatorArrayDeclaration(WhidbeyBaseValidator validator, Type validatorType) {
string element = "document.getElementById(\"" + validator.ClientID + "\")";
ScriptManager.RegisterArrayDeclaration(validator, "Page_Validators", element);

ScriptManager.RegisterStartupScript(validator, validatorType, validator.ClientID + "_DisposeScript",
String.Format(
CultureInfo.InvariantCulture,
@dotnet.itags.org."
document.getElementById('{0}').dispose = function() {{
Array.remove(Page_Validators, document.getElementById('{0}'));
}}; <-- *** PROBLEM HERE ***
",
validator.ClientID), true);
}

...and everything works fine.

Sean

Hi Sean,

Thanks for your sharing.
Please reply to this thread and mark your post as answer so that it will contribute more to others.
Thank you.

I contacted Matt Gibbs (MS) and he said it was too late for this to make it into the next update to System.Web, but the fix will make it into Orcas.

Sean

No comments:

Post a Comment