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[i];
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
--
Milosz
"Mark Rae" wrote:
"Mike Chen" <ch****@gmail.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
We know in server code, we can check the page validated by using
Page.IsValid where we put some validator controls on aspx page.
I want to set some value after validating user input values on client side
and before page posts to server. How can i get the functionality of client
side Page.IsValid? thanks.
I have my own set of JavaScript routines for this.
I don't use the validator controls at all, unless I absolutely have to (e.g.
for custom controls), as I find them incredibly cumbersome and restrictive.