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.Button))] 00013 public class Button : ASP.Button, IUpdatableControl, ICallBackControl 00014 { 00015 #region Unique Anthem control code 00016 00021 protected override void AddAttributesToRender(HtmlTextWriter writer) 00022 { 00023 Anthem.Manager.AddScriptAttribute( 00024 this, 00025 "onclick", 00026 Anthem.Manager.GetCallbackEventReference( 00027 this, 00028 this.CausesValidation, 00029 #if V2 00030 this.ValidationGroup 00031 #else 00032 string.Empty 00033 #endif 00034 ) + "return false;" 00035 ); 00036 base.AddAttributesToRender(writer); 00037 } 00038 00039 private const string parentTagName = "span"; 00044 protected override void Render(HtmlTextWriter writer) 00045 { 00046 #if !V2 00047 bool DesignMode = this.Context == null; 00048 #endif 00049 if (!DesignMode) 00050 { 00051 Anthem.Manager.WriteBeginControlMarker(writer, parentTagName, this); 00052 } 00053 if (Visible) 00054 { 00055 base.Render(writer); 00056 } 00057 if (!DesignMode) 00058 { 00059 Anthem.Manager.WriteEndControlMarker(writer, parentTagName, this); 00060 } 00061 } 00062 00063 #endregion 00064 00065 #region ICallBackControl implementation 00066 00071 [Category("Anthem")] 00072 [DefaultValue("")] 00073 [Description("The javascript function to call on the client if the callback is cancelled.")] 00074 public virtual string CallBackCancelledFunction 00075 { 00076 get 00077 { 00078 string text = (string)ViewState["CallBackCancelledFunction"]; 00079 if (text == null) 00080 return string.Empty; 00081 else 00082 return text; 00083 } 00084 set 00085 { 00086 ViewState["CallBackCancelledFunction"] = value; 00087 } 00088 } 00089 00097 [Category("Anthem")] 00098 [DefaultValue(true)] 00099 [Description("True if this control uses callbacks instead of postbacks to post data to the server.")] 00100 public virtual bool EnableCallBack 00101 { 00102 get 00103 { 00104 object obj = this.ViewState["EnableCallBack"]; 00105 if (obj == null) 00106 return true; 00107 else 00108 return (bool)obj; 00109 } 00110 set 00111 { 00112 ViewState["EnableCallBack"] = value; 00113 } 00114 } 00115 00124 [Category("Anthem")] 00125 [DefaultValue(true)] 00126 [Description("True if this control is enabled on the client during callbacks.")] 00127 public virtual bool EnabledDuringCallBack 00128 { 00129 get 00130 { 00131 object obj = this.ViewState["EnabledDuringCallBack"]; 00132 if (obj == null) 00133 return true; 00134 else 00135 return (bool)obj; 00136 } 00137 set 00138 { 00139 ViewState["EnabledDuringCallBack"] = value; 00140 } 00141 } 00142 00143 00161 [Category("Anthem")] 00162 [DefaultValue("")] 00163 [Description("The javascript function to call on the client after the callback response is received.")] 00164 public virtual string PostCallBackFunction 00165 { 00166 get 00167 { 00168 string text = (string)this.ViewState["PostCallBackFunction"]; 00169 if (text == null) 00170 { 00171 return string.Empty; 00172 } 00173 return text; 00174 } 00175 set 00176 { 00177 ViewState["PostCallBackFunction"] = value; 00178 } 00179 } 00180 00186 [Category("Anthem")] 00187 [DefaultValue("")] 00188 [Description("The javascript function to call on the client before the callback is made.")] 00189 public virtual string PreCallBackFunction 00190 { 00191 get 00192 { 00193 string text = (string)this.ViewState["PreCallBackFunction"]; 00194 if (text == null) 00195 { 00196 return string.Empty; 00197 } 00198 return text; 00199 } 00200 set 00201 { 00202 ViewState["PreCallBackFunction"] = value; 00203 } 00204 } 00205 00214 [Category("Anthem")] 00215 [DefaultValue("")] 00216 [Description("The text to display during the callback.")] 00217 public virtual string TextDuringCallBack 00218 { 00219 get 00220 { 00221 string text = (string)this.ViewState["TextDuringCallBack"]; 00222 if (text == null) 00223 { 00224 return string.Empty; 00225 } 00226 return text; 00227 } 00228 set 00229 { 00230 ViewState["TextDuringCallBack"] = value; 00231 } 00232 } 00233 00234 #endregion 00235 00236 #region IUpdatableControl implementation 00237 00251 [Category("Anthem")] 00252 [DefaultValue(false)] 00253 [Description("True if this control should be updated after each callback.")] 00254 public virtual bool AutoUpdateAfterCallBack 00255 { 00256 get 00257 { 00258 object obj = this.ViewState["AutoUpdateAfterCallBack"]; 00259 if (obj == null) 00260 return false; 00261 else 00262 return (bool)obj; 00263 } 00264 set 00265 { 00266 if (value) UpdateAfterCallBack = true; 00267 ViewState["AutoUpdateAfterCallBack"] = value; 00268 } 00269 } 00270 00271 private bool _updateAfterCallBack = false; 00272 00287 [Browsable(false)] 00288 [DefaultValue(false)] 00289 public virtual bool UpdateAfterCallBack 00290 { 00291 get { return _updateAfterCallBack; } 00292 set { _updateAfterCallBack = value; } 00293 } 00294 00295 #endregion 00296 00297 #region Common Anthem control code 00298 00304 protected override void OnLoad(EventArgs e) 00305 { 00306 base.OnLoad(e); 00307 Anthem.Manager.Register(this); 00308 } 00309 00310 #if V2 00314 public override void RenderControl(HtmlTextWriter writer) 00315 { 00316 base.Visible = true; 00317 base.RenderControl(writer); 00318 } 00319 #endif 00320 00328 public override bool Visible 00329 { 00330 get 00331 { 00332 #if !V2 00333 bool DesignMode = this.Context == null; 00334 #endif 00335 return Anthem.Manager.GetControlVisible(this, ViewState, DesignMode); 00336 } 00337 set { Anthem.Manager.SetControlVisible(ViewState, value); } 00338 } 00339 00340 #endregion 00341 } 00342 }