The second
argument is a structure with an IsValid property that is set to true or false to signal the results
as well as a Value property representing the input value. The ValidateEvent routine uses modulo
arithmetic to detect if a number is even or odd.
Configuring the server-side validation for the same control is done by wiring up the
ValidateEvent method in the code-behind file with the ServerValidate event of the
CustomValidator control. The parameters work in a similar fashion to their JavaScript counterparts
with a Value and IsValid property.
private void ValidateEvent(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
if ((Convert.ToInt32(args.Value) % 2) == 0)
args.IsValid = true;
else
args.IsValid = false;
}
The next two sections provide a high-level overview of namespaces introduced in ASP.NET 2.0
or later.
40 CHAPTER 1 ?– SERVER CONTROL BASICS
System.Web.UI.WebControls.Adapters Namespace
System.Web.UI.WebControls.Adapters was introduced in ASP.NET 2.0. It allows developers
to build control adapters. An ASP.NET 2.0 control adapter allows developers to plug into any
ASP.NET server control and override, modify, and/or tweak the rendering output logic of that
control. We provide an example adapter in Chapter 10.
Pages:
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91