• Twitter
  • Facebook
  • Google+
  • Instagram
  • Youtube

Friday, April 18, 2008

How to use Custom Validator in Asp.Net

How to use Custom Validator in Asp.Net
---------------------------------------------------

This is the HTML section of Custom Validator Control.

<asp:CustomValidator ID="custVal" runat="Server" ValidationGroup="grpProductAdd"
Display="None" ErrorMessage="Please, Enter Product Amount." ClientValidationFunction="CheckProduct">
</asp:CustomValidator>

We need a javascript function to use Custom Validation that return either 'true' or 'false' result.

<script language="javascript" type="text/javascript">

// You must use this both parameter with your function, because by it Validator validate the result.
function CheckProduct(sender, args)
{
// This is the variable name by which we can identify true/false result.
var Check = 0;


var ProductVal = document.getElementById('txtProductVal').value;
if (ProductVal = '')
{
Check = 0
}
else
{
Check = 1
}


// If your condition become true
if (Check == '0' )
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
</script>

That's It !
Hope you will like it.

0 comments:

Contact

Get in touch with me


Adress/Street

12 Street West Victoria 1234 Australia

Phone number

+(12) 3456 789

Website

www.johnsmith.com