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:RequiredFi eldValidator runat="server" ID="rfvName"
ControlToValida te="txtName" ErrorMessage="G ot ya!" EnableClientScr ipt="true"/>
<asp:Button runat="server" ID="btnSubmit" CausesValidatio n="false"
Text="Submit!" OnClientClick=" return ValidateOrShowD ialogBox2()"/>
<script type="text/javascript">
// example that checks particular validator
function ValidateOrShowD ialogBox()
{
var validator = document.getEle mentById('<%=rf vName.ClientID %>');
ValidatorValida te(validator);
// you can use Page_Validators array instead
if (validator.isva lid)
{
// 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 ValidateOrShowD ialogBox2()
{
var validator;
for (var i = 0; i < Page_Validators .length; i++)
{
validator = Page_Validators[i];
ValidatorValida te(validator);
// validation fails if at least one validator fails
if (!validator.isv alid)
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 ValidationSumma ry 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.c omwrote in message
news:%2******** *******@TK2MSFT NGP06.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.