The property handlers
perform data validation tasks to ensure the number set for the Value property falls between the
MinValue and MaxValue property range. We default to System.Int.MaxRange for the MaxValue
property to prevent an exception if the value is too large. Here??™s how these properties are
declared within the UpDown server control:
public virtual int MinValue
{
get
{
EnsureChildControls();
object min = ViewState["MinValue"];
return (min == null) ? 0 : (int) min;
}
set
{
EnsureChildControls();
if (value < MaxValue)
ViewState["MinValue"] = value;
else
throw new ArgumentException(
"MinValue must be less than MaxValue.","MinValue");
}
}
376 CHAPTER 8 ?– I NTEGRAT ING CLI ENT-SI D E SCRIPT
public virtual int MaxValue
{
get
{
EnsureChildControls();
object max = ViewState["MaxValue"];
return (max == null) ? System.Int32.MaxValue : (int) max;
}
set
{
EnsureChildControls();
if (value > MinValue)
ViewState["MaxValue"] = value;
else
throw new ArgumentException(
"MaxValue must be greater than MinValue.","MaxValue");
}
}
public int Value
{
get
{
EnsureChildControls();
object value = (int)ViewState["value"];
return (value != null) ? (int)value : 0;
}
set
{
EnsureChildControls();
if ((value <= MaxValue) &&
(value >= MinValue))
{
valueTextBox.
Pages:
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493