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.ValidationSummary))]
00013 public class ValidationSummary : ASP.ValidationSummary, IUpdatableControl
00014 {
00015 #region Unique Anthem control code
00016
00021 [Category("Anthem")]
00022 [DefaultValue(true)]
00023 [Description("Gets or sets a value which indicates whether the control should display the validation summary as a client-side alert.")]
00024 public virtual bool EnableCallBackScript
00025 {
00026 get
00027 {
00028 object obj = this.ViewState["EnableCallBackScript"];
00029 if (obj == null)
00030 return false;
00031 else
00032 return (bool)obj;
00033 }
00034 set
00035 {
00036 ViewState["EnableCallBackScript"] = value;
00037 }
00038 }
00039
00045 protected override void OnPreRender(EventArgs e)
00046 {
00047 base.OnPreRender(e);
00048
00049 bool isValid = true;
00050 foreach (IValidator validator in Page.Validators)
00051 isValid &= validator.IsValid;
00052
00053 if (Anthem.Manager.IsCallBack
00054 && !isValid
00055 && this.ShowMessageBox
00056 && this.EnableCallBackScript)
00057 {
00058 string s = string.Empty;
00059 if (this.HeaderText != null && this.HeaderText != string.Empty)
00060 s += this.HeaderText + "\\n";
00061 int count = 0;
00062 foreach (ASP.BaseValidator validator in Page.Validators)
00063 {
00064
00065 #if V2
00066 if (
00067 ((
00068 (this.ValidationGroup == null || this.ValidationGroup == string.Empty)
00069 && (validator.ValidationGroup == null || validator.ValidationGroup == string.Empty)
00070 )
00071 ||
00072 (
00073 (this.ValidationGroup != null && this.ValidationGroup != string.Empty)
00074 && (validator.ValidationGroup != null && validator.ValidationGroup == this.ValidationGroup)
00075 ))
00076 && !validator.IsValid
00077 && validator.ErrorMessage != null
00078 && validator.ErrorMessage != string.Empty)
00079 #else
00080 if (!validator.IsValid
00081 && validator.ErrorMessage != null
00082 && validator.ErrorMessage != string.Empty)
00083 #endif
00084
00085 {
00086 count++;
00087 switch (this.DisplayMode)
00088 {
00089 case System.Web.UI.WebControls.ValidationSummaryDisplayMode.List:
00090 s += validator.ErrorMessage + "\\n";
00091 break;
00092 case System.Web.UI.WebControls.ValidationSummaryDisplayMode.BulletList:
00093 default:
00094 s += " - " + validator.ErrorMessage + "\\n";
00095 break;
00096 case System.Web.UI.WebControls.ValidationSummaryDisplayMode.SingleParagraph:
00097 s += validator.ErrorMessage + " ";
00098 break;
00099 }
00100 }
00101 }
00102 if (count > 0)
00103 Anthem.Manager.AddScriptForClientSideEval("alert('" + s + "');");
00104 }
00105 }
00106
00107 private const string parentTagName = "div";
00112 protected override void Render(HtmlTextWriter writer)
00113 {
00114 #if !V2
00115 bool DesignMode = this.Context == null;
00116 #endif
00117 if (!DesignMode)
00118 {
00119 Anthem.Manager.WriteBeginControlMarker(writer, parentTagName, this);
00120 }
00121 if (Visible)
00122 {
00123 base.Render(writer);
00124 }
00125 if (!DesignMode)
00126 {
00127 Anthem.Manager.WriteEndControlMarker(writer, parentTagName, this);
00128 }
00129 }
00130
00131 #endregion
00132
00133 #region IUpdatableControl implementation
00134
00148 [Category("Anthem")]
00149 [DefaultValue(false)]
00150 [Description("True if this control should be updated after each callback.")]
00151 public virtual bool AutoUpdateAfterCallBack
00152 {
00153 get
00154 {
00155 object obj = this.ViewState["AutoUpdateAfterCallBack"];
00156 if (obj == null)
00157 return false;
00158 else
00159 return (bool)obj;
00160 }
00161 set
00162 {
00163 if (value) UpdateAfterCallBack = true;
00164 ViewState["AutoUpdateAfterCallBack"] = value;
00165 }
00166 }
00167
00168 private bool _updateAfterCallBack = false;
00169
00184 [Browsable(false)]
00185 [DefaultValue(false)]
00186 public virtual bool UpdateAfterCallBack
00187 {
00188 get { return _updateAfterCallBack; }
00189 set { _updateAfterCallBack = value; }
00190 }
00191
00192 #endregion
00193
00194 #region Common Anthem control code
00195
00201 protected override void OnLoad(EventArgs e)
00202 {
00203 base.OnLoad(e);
00204 Anthem.Manager.Register(this);
00205 }
00206
00207 #if V2
00211 public override void RenderControl(HtmlTextWriter writer)
00212 {
00213 base.Visible = true;
00214 base.RenderControl(writer);
00215 }
00216 #endif
00217
00225 public override bool Visible
00226 {
00227 get
00228 {
00229 #if !V2
00230 bool DesignMode = this.Context == null;
00231 #endif
00232 return Anthem.Manager.GetControlVisible(this, ViewState, DesignMode);
00233 }
00234 set { Anthem.Manager.SetControlVisible(ViewState, value); }
00235 }
00236
00237 #endregion
00238 }
00239 }