Empty);
}
}
At this point, our data loading and event raising tasks are complete. Our control is prepared to
render in the browser. Listing 8-11 presents the full source code for the UpDown control. Listing
8-12 contains the UpDown.js JavaScript file.
CHAPTER 8 ?– INTEGRATING CL IENT-SIDE SCRIPT 385
Listing 8-11. The UpDown Server Control
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
[assembly: WebResource("ControlsBook2Lib.Ch08.UpDown.js", "text/javascript")]
namespace ControlsBook2Lib.Ch08
{
[ToolboxData("<{0}:UpDown runat=server>{0}:UpDown>"),
DefaultProperty("Value")]
public class UpDown : WebControl, IPostBackDataHandler, INamingContainer
{
protected const string UP_FUNC = "__UpDown_Up";
protected const string DOWN_FUNC = "__UpDown_Down";
protected string CHECK_FUNC = "__UpDown_Check";
private TextBox valueTextBox ;
private Button upButton ;
private Button downButton ;
private bool renderClientScript;
private static readonly object ValueChangedKey = new object();
public UpDown() : base(HtmlTextWriterTag.Div)
{
renderClientScript = false;
}
public virtual bool EnableClientScript
{
get
{
EnsureChildControls();
object script = ViewState["EnableClientScript"];
if (script == null)
return true;
else
return (bool) script;
}
386 CHAPTER 8 ?– I NTEGRAT ING CLI ENT-SI D E SCRIPT
set
{
EnsureChildControls();
ViewState["EnableClientScript"] = value;
}
}
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.
Pages:
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506