using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace
Validators
{
public partial class ValidatorsExample3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//
Checks to see if all the custom validator controls successfully validated
if (Page.IsValid)
lblMessage.Text
= "The employee was recorded
successfully.";
else
lblMessage.Text
= "There was a problem with some of
the data entered.";
}
protected void valRate_ServerValidate(object source, ServerValidateEventArgs args)
{
double hourlyRate = 0;
// Check
the value of the control this validator is validating
if (double.TryParse(args.Value, out hourlyRate)
&& hourlyRate != double.NaN)
{
//set
the validator to valid and also used to set the Page.IsValid
to true
args.IsValid
= true;
}
else
{
//
set the validator to invalid and also sets the Page.IsValid
to false
args.IsValid
= false;
}
}
protected void valSecurityLevel_ServerValidate(object source, ServerValidateEventArgs args)
{
int level = -1;
// Check
the value of the control this validator is validating
if (int.TryParse(args.Value, out level))
{
if( level >= 0 && level <= 5)
{
// set the validator to valid and also used to set the Page.IsValid to true
args.IsValid
= true;
}
else
{
// set the validator to invalid and also sets the Page.IsValid to false
args.IsValid
= false;
}
}
else
{
// set the validator to invalid and also sets the Page.IsValid to false
args.IsValid
= false;
}
}
}
}