I have a asp.net page accepting two input values – Name and Address. Both of them are required fields. I have used required field validators and validation summary.
Whe
This is a little hackish, but it'll work:
Add the following Javascript function:
function submitValidate() {
var isValid = Page_ClientValidate('');
if (!isValid) {
setTimeout("$('#vsumAll ul li:not(:first)').remove()", 5);
}
return isValid;
}
In your submit button add this:
<asp:Button runat="server" ID="btnSave" Text="Save" OnClientClick="submitValidate();"/>
And finaly, make sure you have ClientIDMode="Static"
on your ValidationSummary
Explanation:
It uses JQuery to remove all but the first li
in the ValidationSummary - which is actually an UnorderedList (e.g. ul
).
I put it in a 5ms setTimeout
since we want it to run only after the ValidationSummary finished adding all the items to the ul
.
The code will only run if Page_ClientValidate
fails - this is the function that performs the ClientSide validation.