Hi Mark and Mike,
Of course there is. ASP.NET provides nice client side API to support custom,
non standard scenarios. In addtion to that Mark, there is no need for coding
such functionality on your own as provided API can solve 99% cases. Let me
give you a simple example how to validate the page youself using client side
API:
<asp:TextBox runat="server" ID="txtName"/>
<asp:RequiredFieldValidator runat="server" ID="rfvName"
ControlToValidate="txtName" ErrorMessage="Got ya!" EnableClientScript="true"/>
<asp:Button runat="server" ID="btnSubmit" CausesValidation="false"
Text="Submit!" OnClientClick="return ValidateOrShowDialogBox2()"/>
<script type="text/javascript">
// example that checks particular validator
function ValidateOrShowDialogBox()
{
var validator = document.getElementById('<%=rfvName.ClientID %>');
ValidatorValidate(validator);
// you can use Page_Validators array instead
if (validator.isvalid)
{
// create dialog box here
alert('well done!');
}
// set it to true to post back page
return false;
}
// example that checks all validators on the page
function ValidateOrShowDialogBox2()
{
var validator;
for (var i = 0; i < Page_Validators.length; i++)
{
validator = Page_Validators;
ValidatorValidate(validator);
// validation fails if at least one validator fails
if (!validator.isvalid)
return false;
}
// create dialog box here
alert('well done!');
// set it to true to post back page
return false;
}
</script>
One more thing. You may apply several validators to the same control (in
conjunction with ValidationSummary control and/or Display property of the
validator) which is a quick and efficient way of building validation chain.
Regards guys