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.DataGrid))] 00013 public class DataGrid : ASP.DataGrid, IUpdatableControl, ICallBackContainerControl 00014 { 00015 #region Unique Anthem control code 00016 00021 protected override void OnCancelCommand(System.Web.UI.WebControls.DataGridCommandEventArgs e) 00022 { 00023 base.OnCancelCommand(e); 00024 this.UpdateAfterCallBack = true; 00025 } 00026 00031 protected override void OnDeleteCommand(System.Web.UI.WebControls.DataGridCommandEventArgs e) 00032 { 00033 base.OnDeleteCommand(e); 00034 this.UpdateAfterCallBack = true; 00035 } 00036 00041 protected override void OnEditCommand(System.Web.UI.WebControls.DataGridCommandEventArgs e) 00042 { 00043 base.OnEditCommand(e); 00044 this.UpdateAfterCallBack = true; 00045 } 00046 00051 protected override void OnItemCommand(System.Web.UI.WebControls.DataGridCommandEventArgs e) 00052 { 00053 base.OnItemCommand(e); 00054 this.UpdateAfterCallBack = true; 00055 } 00056 00061 protected override void OnPageIndexChanged(System.Web.UI.WebControls.DataGridPageChangedEventArgs e) 00062 { 00063 base.OnPageIndexChanged(e); 00064 this.UpdateAfterCallBack = true; 00065 } 00066 00071 protected override void OnSelectedIndexChanged(EventArgs e) 00072 { 00073 base.OnSelectedIndexChanged(e); 00074 this.UpdateAfterCallBack = true; 00075 } 00076 00081 protected override void OnSortCommand(System.Web.UI.WebControls.DataGridSortCommandEventArgs e) 00082 { 00083 base.OnSortCommand(e); 00084 this.UpdateAfterCallBack = true; 00085 } 00086 00091 protected override void OnUpdateCommand(System.Web.UI.WebControls.DataGridCommandEventArgs e) 00092 { 00093 base.OnUpdateCommand(e); 00094 this.UpdateAfterCallBack = true; 00095 } 00096 00097 private const string parentTagName = "div"; 00102 protected override void Render(HtmlTextWriter writer) 00103 { 00104 #if !V2 00105 bool DesignMode = this.Context == null; 00106 #endif 00107 if (EnableCallBack && AddCallBacks) 00108 Anthem.Manager.AddCallBacks(this, 00109 EnabledDuringCallBack, 00110 TextDuringCallBack, 00111 PreCallBackFunction, 00112 PostCallBackFunction, 00113 CallBackCancelledFunction); 00114 00115 if (!DesignMode) 00116 { 00117 Anthem.Manager.WriteBeginControlMarker(writer, parentTagName, this); 00118 } 00119 if (Visible) 00120 { 00121 base.Render(writer); 00122 } 00123 if (!DesignMode) 00124 { 00125 Anthem.Manager.WriteEndControlMarker(writer, parentTagName, this); 00126 } 00127 } 00128 00129 #endregion 00130 00131 #region ICallBackControl implementation 00132 00137 [Category("Anthem")] 00138 [DefaultValue("")] 00139 [Description("The javascript function to call on the client if the callback is cancelled.")] 00140 public virtual string CallBackCancelledFunction 00141 { 00142 get 00143 { 00144 string text = (string)ViewState["CallBackCancelledFunction"]; 00145 if (text == null) 00146 return string.Empty; 00147 else 00148 return text; 00149 } 00150 set 00151 { 00152 ViewState["CallBackCancelledFunction"] = value; 00153 } 00154 } 00155 00163 [Category("Anthem")] 00164 [DefaultValue(true)] 00165 [Description("True if this control uses callbacks instead of postbacks to post data to the server.")] 00166 public virtual bool EnableCallBack 00167 { 00168 get 00169 { 00170 object obj = this.ViewState["EnableCallBack"]; 00171 if (obj == null) 00172 return true; 00173 else 00174 return (bool)obj; 00175 } 00176 set 00177 { 00178 ViewState["EnableCallBack"] = value; 00179 } 00180 } 00181 00190 [Category("Anthem")] 00191 [DefaultValue(true)] 00192 [Description("True if this control is enabled on the client during callbacks.")] 00193 public virtual bool EnabledDuringCallBack 00194 { 00195 get 00196 { 00197 object obj = this.ViewState["EnabledDuringCallBack"]; 00198 if (obj == null) 00199 return true; 00200 else 00201 return (bool)obj; 00202 } 00203 set 00204 { 00205 ViewState["EnabledDuringCallBack"] = value; 00206 } 00207 } 00208 00209 00227 [Category("Anthem")] 00228 [DefaultValue("")] 00229 [Description("The javascript function to call on the client after the callback response is received.")] 00230 public virtual string PostCallBackFunction 00231 { 00232 get 00233 { 00234 string text = (string)this.ViewState["PostCallBackFunction"]; 00235 if (text == null) 00236 { 00237 return string.Empty; 00238 } 00239 return text; 00240 } 00241 set 00242 { 00243 ViewState["PostCallBackFunction"] = value; 00244 } 00245 } 00246 00252 [Category("Anthem")] 00253 [DefaultValue("")] 00254 [Description("The javascript function to call on the client before the callback is made.")] 00255 public virtual string PreCallBackFunction 00256 { 00257 get 00258 { 00259 string text = (string)this.ViewState["PreCallBackFunction"]; 00260 if (text == null) 00261 { 00262 return string.Empty; 00263 } 00264 return text; 00265 } 00266 set 00267 { 00268 ViewState["PreCallBackFunction"] = value; 00269 } 00270 } 00271 00280 [Category("Anthem")] 00281 [DefaultValue("")] 00282 [Description("The text to display during the callback.")] 00283 public virtual string TextDuringCallBack 00284 { 00285 get 00286 { 00287 string text = (string)this.ViewState["TextDuringCallBack"]; 00288 if (text == null) 00289 { 00290 return string.Empty; 00291 } 00292 return text; 00293 } 00294 set 00295 { 00296 ViewState["TextDuringCallBack"] = value; 00297 } 00298 } 00299 00300 #endregion 00301 00302 #region ICallBackContainerControl implementation 00303 00315 [Category("Anthem")] 00316 [DefaultValue(true)] 00317 [Description("True if this control should convert child control postbacks into callbacks.")] 00318 public virtual bool AddCallBacks 00319 { 00320 get 00321 { 00322 object obj = this.ViewState["AddCallBacks"]; 00323 if (obj == null) 00324 return true; 00325 else 00326 return (bool)obj; 00327 } 00328 set 00329 { 00330 ViewState["AddCallBacks"] = value; 00331 } 00332 } 00333 00334 #endregion 00335 00336 #region IUpdatableControl implementation 00337 00351 [Category("Anthem")] 00352 [DefaultValue(false)] 00353 [Description("True if this control should be updated after each callback.")] 00354 public virtual bool AutoUpdateAfterCallBack 00355 { 00356 get 00357 { 00358 object obj = this.ViewState["AutoUpdateAfterCallBack"]; 00359 if (obj == null) 00360 return false; 00361 else 00362 return (bool)obj; 00363 } 00364 set 00365 { 00366 if (value) UpdateAfterCallBack = true; 00367 ViewState["AutoUpdateAfterCallBack"] = value; 00368 } 00369 } 00370 00371 private bool _updateAfterCallBack = false; 00372 00387 [Browsable(false)] 00388 [DefaultValue(false)] 00389 public virtual bool UpdateAfterCallBack 00390 { 00391 get { return _updateAfterCallBack; } 00392 set { _updateAfterCallBack = value; } 00393 } 00394 00395 #endregion 00396 00397 #region Common Anthem control code 00398 00404 protected override void OnLoad(EventArgs e) 00405 { 00406 base.OnLoad(e); 00407 Anthem.Manager.Register(this); 00408 } 00409 00410 #if V2 00414 public override void RenderControl(HtmlTextWriter writer) 00415 { 00416 base.Visible = true; 00417 base.RenderControl(writer); 00418 } 00419 #endif 00420 00428 public override bool Visible 00429 { 00430 get 00431 { 00432 #if !V2 00433 bool DesignMode = this.Context == null; 00434 #endif 00435 return Anthem.Manager.GetControlVisible(this, ViewState, DesignMode); 00436 } 00437 set { Anthem.Manager.SetControlVisible(ViewState, value); } 00438 } 00439 00440 #endregion 00441 } 00442 }