We add
server-side event handlers to both upButton and downButton, in case we need them because
either the client-side script is not enabled or the browser does not support the level of DOM
access required. In the next section, we discuss how the UpDown control provides a smooth
experience to the end user with a discussion of how the server control monitors for value changes.
The ValueChanged Event
Our server control makes it easy to monitor the UpDown control and be notified only when it
changes value through a server-side event named ValueChanged. The ValueChanged event is
raised when it detects a difference between the Value property of the control from ViewState
and what is received from the client after a postback:
public event EventHandler ValueChanged
{
add
{
Events.AddHandler(ValueChangedKey, value);
}
remove
{
Events.RemoveHandler(ValueChangedKey, value);
}
}
protected virtual void OnValueChanged(EventArgs e)
{
EventHandler valueChangedEventDelegate =
(EventHandler) Events[ValueChangedKey];
CHAPTER 8 ?– INTEGRATING CL IENT-SIDE SCRIPT 383
if (valueChangedEventDelegate != null)
{
valueChangedEventDelegate(this, e);
}
}
ValueChanged follows the basic pattern of the System.EventHandler delegate for its event
declaration, so we can reuse the System.
Pages:
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502