D:/Projects/Anthem/Anthem/CheckBoxList.cs

00001 using System;
00002 using System.ComponentModel;
00003 using System.Drawing;
00004 using System.Web.UI;
00005 using ASP = System.Web.UI.WebControls;
00006 
00007 namespace Anthem
00008 {
00012     [ToolboxBitmap(typeof(ASP.CheckBoxList))]
00013     public class CheckBoxList : ASP.CheckBoxList, IUpdatableControl, ICallBackControl
00014     {
00015         #region Unique Anthem control code
00016 
00021         [DefaultValue(false)]
00022         public bool AutoCallBack
00023         {
00024             get
00025             {
00026                 if (null == ViewState["AutoCallBack"])
00027                     return false;
00028                 else
00029                     return (bool)ViewState["AutoCallBack"];
00030             }
00031             set { ViewState["AutoCallBack"] = value; }
00032         }
00033 
00034 #if V2
00040         [Category("Default")]
00041         [DefaultValue("")]
00042         [MergableProperty(false)]
00043         [PersistenceMode(PersistenceMode.InnerProperty)]
00044         public override System.Web.UI.WebControls.ListItemCollection Items
00045         {
00046             get
00047             {
00048                 return base.Items;
00049             }
00050         }
00051 #endif
00052 
00056         protected override void OnPreRender(EventArgs e)
00057         {
00058             base.OnPreRender(e);
00059             if (AutoCallBack)
00060             {
00061                 Anthem.Manager.AddScriptAttribute(
00062                     this,
00063                     "onclick",
00064                     string.Format(
00065                         "AnthemListControl_OnClick(event,{0},'{1}','{2}',{3},{4},{5},{6});",
00066 #if V2
00067                         this.CausesValidation ? "true" : "false",
00068                         this.ValidationGroup,
00069 #else
00070                         "false",
00071                         string.Empty,
00072 #endif
00073                         this.TextDuringCallBack,
00074                         this.EnabledDuringCallBack ? "true" : "false",
00075                         (this.PreCallBackFunction == null || this.PreCallBackFunction.Length == 0) ? "null" : this.PreCallBackFunction,
00076                         (this.PostCallBackFunction == null || this.PostCallBackFunction.Length == 0) ? "null" : this.PostCallBackFunction,
00077                         (this.CallBackCancelledFunction == null || this.CallBackCancelledFunction.Length == 0) ? "null" : this.CallBackCancelledFunction
00078                     )
00079                 );
00080                 // Disable postback so there is no double callback+postback
00081                 ASP.CheckBox controlToRepeat = (ASP.CheckBox)this.Controls[0];
00082                 controlToRepeat.AutoPostBack = false;
00083             }
00084         }
00085 
00090         protected override void Render(HtmlTextWriter writer)
00091         {
00092 #if !V2
00093             bool DesignMode = this.Context == null;
00094 #endif
00095             if (!DesignMode)
00096             {
00097                 Anthem.Manager.WriteBeginControlMarker(writer, this.RepeatLayout == ASP.RepeatLayout.Flow ? "span" : "div", this);
00098             }
00099             if (Visible)
00100             {
00101                 base.Render(writer);
00102             }
00103             if (!DesignMode)
00104             {
00105                 Anthem.Manager.WriteEndControlMarker(writer, this.RepeatLayout == ASP.RepeatLayout.Flow ? "span" : "div", this);
00106             }
00107         }
00108 
00109         #endregion
00110 
00111         #region ICallBackControl implementation
00112 
00117         [Category("Anthem")]
00118         [DefaultValue("")]
00119         [Description("The javascript function to call on the client if the callback is cancelled.")]
00120         public virtual string CallBackCancelledFunction
00121         {
00122             get
00123             {
00124                 string text = (string)ViewState["CallBackCancelledFunction"];
00125                 if (text == null)
00126                     return string.Empty;
00127                 else
00128                     return text;
00129             }
00130             set
00131             {
00132                 ViewState["CallBackCancelledFunction"] = value;
00133             }
00134         }
00135 
00143         [Category("Anthem")]
00144         [DefaultValue(true)]
00145         [Description("True if this control uses callbacks instead of postbacks to post data to the server.")]
00146         public virtual bool EnableCallBack
00147         {
00148             get
00149             {
00150                 object obj = this.ViewState["EnableCallBack"];
00151                 if (obj == null)
00152                     return true;
00153                 else
00154                     return (bool)obj;
00155             }
00156             set
00157             {
00158                 ViewState["EnableCallBack"] = value;
00159             }
00160         }
00161 
00170         [Category("Anthem")]
00171         [DefaultValue(true)]
00172         [Description("True if this control is enabled on the client during callbacks.")]
00173         public virtual bool EnabledDuringCallBack
00174         {
00175             get
00176             {
00177                 object obj = this.ViewState["EnabledDuringCallBack"];
00178                 if (obj == null)
00179                     return true;
00180                 else
00181                     return (bool)obj;
00182             }
00183             set
00184             {
00185                 ViewState["EnabledDuringCallBack"] = value;
00186             }
00187         }
00188 
00189 
00207         [Category("Anthem")]
00208         [DefaultValue("")]
00209         [Description("The javascript function to call on the client after the callback response is received.")]
00210         public virtual string PostCallBackFunction
00211         {
00212             get
00213             {
00214                 string text = (string)this.ViewState["PostCallBackFunction"];
00215                 if (text == null)
00216                 {
00217                     return string.Empty;
00218                 }
00219                 return text;
00220             }
00221             set
00222             {
00223                 ViewState["PostCallBackFunction"] = value;
00224             }
00225         }
00226 
00232         [Category("Anthem")]
00233         [DefaultValue("")]
00234         [Description("The javascript function to call on the client before the callback is made.")]
00235         public virtual string PreCallBackFunction
00236         {
00237             get
00238             {
00239                 string text = (string)this.ViewState["PreCallBackFunction"];
00240                 if (text == null)
00241                 {
00242                     return string.Empty;
00243                 }
00244                 return text;
00245             }
00246             set
00247             {
00248                 ViewState["PreCallBackFunction"] = value;
00249             }
00250         }
00251 
00260         [Category("Anthem")]
00261         [DefaultValue("")]
00262         [Description("The text to display during the callback.")]
00263         public virtual string TextDuringCallBack
00264         {
00265             get
00266             {
00267                 string text = (string)this.ViewState["TextDuringCallBack"];
00268                 if (text == null)
00269                 {
00270                     return string.Empty;
00271                 }
00272                 return text;
00273             }
00274             set
00275             {
00276                 ViewState["TextDuringCallBack"] = value;
00277             }
00278         }
00279 
00280         #endregion
00281 
00282         #region IUpdatableControl implementation
00283 
00297         [Category("Anthem")]
00298         [DefaultValue(false)]
00299         [Description("True if this control should be updated after each callback.")]
00300         public virtual bool AutoUpdateAfterCallBack
00301         {
00302             get
00303             {
00304                 object obj = this.ViewState["AutoUpdateAfterCallBack"];
00305                 if (obj == null)
00306                     return false;
00307                 else
00308                     return (bool)obj;
00309             }
00310             set
00311             {
00312                 if (value) UpdateAfterCallBack = true;
00313                 ViewState["AutoUpdateAfterCallBack"] = value;
00314             }
00315         }
00316 
00317         private bool _updateAfterCallBack = false;
00318 
00333         [Browsable(false)]
00334         [DefaultValue(false)]
00335         public virtual bool UpdateAfterCallBack
00336         {
00337             get { return _updateAfterCallBack; }
00338             set { _updateAfterCallBack = value; }
00339         }
00340 
00341         #endregion
00342 
00343         #region Common Anthem control code
00344 
00350         protected override void OnLoad(EventArgs e)
00351         {
00352             base.OnLoad(e);
00353             Anthem.Manager.Register(this);
00354         }
00355 
00356 #if V2
00360         public override void RenderControl(HtmlTextWriter writer)
00361         {
00362             base.Visible = true;
00363             base.RenderControl(writer);
00364         }
00365 #endif
00366 
00374         public override bool Visible
00375         {
00376             get
00377             {
00378 #if !V2
00379                 bool DesignMode = this.Context == null;
00380 #endif
00381                 return Anthem.Manager.GetControlVisible(this, ViewState, DesignMode);
00382             }
00383             set { Anthem.Manager.SetControlVisible(ViewState, value); }
00384         }
00385 
00386         #endregion
00387     }
00388 }
00389 

Generated on Wed Mar 14 23:50:39 2007 for Anthem by  doxygen 1.5.1-p1