Friday, June 09, 2006
Client-Side Script Breaks Validators No More!
Recently I was using an image button with CausesValidation = true in an ASP.NET page. The inception also has an OnClientClick event and validators. What I discovered was that the client-side script caused an invalid validator to be ignored and the validation summary wasn't displayed. To fix this problem I tapped into the WebUIValidation.js file that gets referenced by ASP.NET pages. (Microsoft ships this javascript file with .NET.)
By manually checking WebUIValidation.Page_IsValid and calling WebUIValidation.ValidationSummaryOnSubmit() if the page is invalid the desired behavior--the validation summary--is now displayed correctly.
Here is the revised code:
function ImageSaveClick()
{
if( !Page_IsValid )
{
ValidationSummaryOnSubmit();
return false;
}
else
return window.confirm("Are you sure?");
}
By manually checking WebUIValidation.Page_IsValid and calling WebUIValidation.ValidationSummaryOnSubmit() if the page is invalid the desired behavior--the validation summary--is now displayed correctly.
Here is the revised code:
function ImageSaveClick()
{
if( !Page_IsValid )
{
ValidationSummaryOnSubmit();
return false;
}
else
return window.confirm("Are you sure?");
}
Subscribe to Posts [Atom]