D:/Projects/Anthem/Anthem/Debugger.cs

00001 using System;
00002 using System.ComponentModel;
00003 using System.Web.UI;
00004 using System.Web.UI.HtmlControls;
00005 using ASP = System.Web.UI.WebControls;
00006 
00007 namespace Anthem
00008 {
00012     public class Debugger : ASP.WebControl, INamingContainer, IUpdatableControl
00013     {
00015         protected override void CreateChildControls()
00016         {
00017             Controls.Add(new LiteralControl("<div><fieldset><legend>Anthem Debugger</legend>"));
00018             AddCheckBox("RequestText");
00019             AddCheckBox("ResponseText");
00020             AddCheckBox("Errors");
00021             Controls.Add(new LiteralControl("</fieldset></div>"));
00022         }
00023 
00024         void AddCheckBox(string option)
00025         {
00026             HtmlInputCheckBox cb = new HtmlInputCheckBox();
00027             Controls.Add(cb);
00028             cb.ID = option;
00029             cb.Attributes["onchange"] = string.Format("AnthemDebugger_Debug{0} = this.checked", option);
00030             Controls.Add(new LiteralControl(string.Format(" {0} ", option)));
00031         }
00032 
00038         protected override void OnLoad(EventArgs e)
00039         {
00040             base.OnLoad(e);
00041 
00042             Anthem.Manager.Register(this);
00043 
00044             if (Page.IsPostBack)
00045             {
00046                 HtmlInputCheckBox requestText = FindControl("RequestText") as HtmlInputCheckBox;
00047                 if (requestText != null)
00048                 {
00049                     DebugRequestText = requestText.Checked;
00050                 }
00051 
00052                 HtmlInputCheckBox responseText = FindControl("ResponseText") as HtmlInputCheckBox;
00053                 if (responseText != null)
00054                 {
00055                     DebugResponseText = responseText.Checked;
00056                 }
00057 
00058                 HtmlInputCheckBox errors = FindControl("Errors") as HtmlInputCheckBox;
00059                 if (errors != null)
00060                 {
00061                     DebugErrors = errors.Checked;
00062                 }
00063             }
00064         }
00065 
00067         protected override void OnPreRender(EventArgs e)
00068         {
00069             base.OnPreRender(e);
00070 
00071             HtmlInputCheckBox requestText = FindControl("RequestText") as HtmlInputCheckBox;
00072             if (requestText != null)
00073             {
00074                 requestText.Checked = DebugRequestText;
00075             }
00076 
00077             HtmlInputCheckBox responseText = FindControl("ResponseText") as HtmlInputCheckBox;
00078             if (responseText != null)
00079             {
00080                 responseText.Checked = DebugResponseText;
00081             }
00082 
00083             HtmlInputCheckBox errors = FindControl("Errors") as HtmlInputCheckBox;
00084             if (errors != null)
00085             {
00086                 errors.Checked = DebugErrors;
00087             }
00088 
00089             string script = string.Format(
00090                 @"<script language='javascript' type='text/javascript'>
var AnthemDebugger_DebugRequestText = {0};
var AnthemDebugger_DebugResponseText = {1};
var AnthemDebugger_DebugErrors = {2};
function Anthem_DebugRequestText(text) {{
    if (AnthemDebugger_DebugRequestText) {{
        alert('Anthem Debugger (RequestText):\n\n' + text);
    }}
}}
function Anthem_DebugResponseText(text) {{
    if (AnthemDebugger_DebugResponseText) {{
        alert('Anthem Debugger (ResponseText):\n\n' + text);
    }}
}}
function Anthem_DebugError(text) {{
    if (AnthemDebugger_DebugErrors) {{
        alert('Anthem Debugger (Error):\n\n' + text);
    }}
}}
</script>",
00091                 DebugRequestText ? "true" : "false",
00092                 DebugResponseText ? "true" : "false",
00093                 DebugErrors ? "true" : "false"
00094             );
00095 
00096 #if V2
00097             Page.ClientScript.RegisterClientScriptBlock(typeof(Debugger), "script", script);
00098 #else
00099             Page.RegisterClientScriptBlock(typeof(Debugger).FullName, script);
00100 #endif
00101         }
00102 
00107         protected override void Render(HtmlTextWriter writer)
00108         {
00109             Anthem.Manager.WriteBeginControlMarker(writer, "div", this);
00110             if (Visible)
00111             {
00112                 base.Render(writer);
00113             }
00114             Anthem.Manager.WriteEndControlMarker(writer, "div", this);
00115         }
00116 
00118         public bool DebugRequestText
00119         {
00120             get
00121             {
00122                 return ViewState["DebugRequestText"] != null
00123                     ? (bool)ViewState["DebugRequestText"]
00124                     : false;
00125             }
00126 
00127             set
00128             {
00129                 if (IsTrackingViewState && Anthem.Manager.IsCallBack && DebugRequestText != value)
00130                 {
00131                     Anthem.Manager.AddScriptForClientSideEval(
00132                         string.Format(
00133                         "AnthemDebugger_DebugRequestText = {0}",
00134                         value ? "true" : "false"));
00135                 }
00136                 ViewState["DebugRequestText"] = value;
00137             }
00138         }
00139 
00141         public bool DebugResponseText
00142         {
00143             get
00144             {
00145                 return ViewState["DebugResponseText"] != null
00146                     ? (bool)ViewState["DebugResponseText"]
00147                     : false;
00148             }
00149 
00150             set
00151             {
00152                 if (IsTrackingViewState && Anthem.Manager.IsCallBack && DebugResponseText != value)
00153                 {
00154                     Anthem.Manager.AddScriptForClientSideEval(
00155                         string.Format(
00156                             "AnthemDebugger_DebugResponseText = {0}",
00157                             value ? "true" : "false"));
00158                 }
00159                 ViewState["DebugResponseText"] = value;
00160             }
00161         }
00162 
00164         public bool DebugErrors
00165         {
00166             get
00167             {
00168                 return ViewState["DebugErrors"] != null
00169                     ? (bool)ViewState["DebugErrors"]
00170                     : false;
00171             }
00172 
00173             set
00174             {
00175                 if (IsTrackingViewState && Anthem.Manager.IsCallBack && DebugErrors != value)
00176                 {
00177                     Anthem.Manager.AddScriptForClientSideEval(
00178                         string.Format(
00179                         "AnthemDebugger_DebugErrors = {0}",
00180                         value ? "true" : "false"));
00181                 }
00182                 ViewState["DebugErrors"] = value;
00183             }
00184         }
00185 
00186         #region Common Anthem control members (copied into each control)
00187 
00188 #if V2
00192         public override void RenderControl(HtmlTextWriter writer)
00193         {
00194             base.Visible = true;
00195             base.RenderControl(writer);
00196         }
00197 #endif
00198 
00206         public override bool Visible
00207         {
00208             get
00209             {
00210 #if !V2
00211                 bool DesignMode = this.Context == null;
00212 #endif
00213                 return Anthem.Manager.GetControlVisible(this, ViewState, DesignMode);
00214             }
00215             set { Anthem.Manager.SetControlVisible(ViewState, value); }
00216         }
00217 
00218         private bool _updateAfterCallBack = false;
00219 
00233         [DefaultValue(false)]
00234         public virtual bool AutoUpdateAfterCallBack
00235         {
00236             get
00237             {
00238                 if (ViewState["AutoUpdateAfterCallBack"] == null)
00239                     return false;
00240                 else
00241                     return (bool)ViewState["AutoUpdateAfterCallBack"];
00242             }
00243             set
00244             {
00245                 if (value) UpdateAfterCallBack = true;
00246                 ViewState["AutoUpdateAfterCallBack"] = value;
00247             }
00248         }
00249 
00264         [Browsable(false), DefaultValue(false)]
00265         public virtual bool UpdateAfterCallBack
00266         {
00267             get { return _updateAfterCallBack; }
00268             set { _updateAfterCallBack = value; }
00269         }
00270 
00278         [DefaultValue(true)]
00279         public virtual bool EnableCallBack
00280         {
00281             get
00282             {
00283                 if (ViewState["EnableCallBack"] == null)
00284                     return true;
00285                 else
00286                     return (bool)ViewState["EnableCallBack"];
00287             }
00288             set
00289             {
00290                 ViewState["EnableCallBack"] = value;
00291             }
00292         }
00293 
00294         #endregion
00295     }
00296 }
00297 

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