18 Eylül 2012 Salı

ASP.NET'de CustomValidator'dan istifadeye aid numune.


Qeyd edim ki, bu nümunədə iki textbox-a Validator tətbiq edilmişdir. Məqsəd validatorla code yazaraq istifadəçi tərəfindən daxil edilən məlumata nəzarət etməkdir.(Bu sadəcə nümunədir)
------------------------------------------------------------------------
Code Behinde'da yaz;lacaq code:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (!string.IsNullOrEmpty(PhoneHome.Text) || !string.IsNullOrEmpty(PhoneBusiness.Text))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
-----------------------------------------------------------------------
Markup view'da yazılacaq code:
<script type="text/javascript">
function ValidatePhoneNumbers(source, args)
{
var phoneHome = document.getElementById('<%= PhoneHome.ClientID %>');
var phoneBusiness = document.getElementById('<%= PhoneBusiness.ClientID %>');
if (phoneHome.value != '' || phoneBusiness.value != '') 
{
args.IsValid = true;
}
else 
{
args.IsValid = false;
}
}
</script>