Author: igorz
Date: 2007-06-19 10:15:55 -0400 (Tue, 19 Jun 2007)
New Revision: 80157

Modified:
   trunk/mcs/class/System.Web.Extensions/System.Web.UI/ScriptManager.cs
   trunk/mcs/class/System.Web.Extensions/System.Web.UI/UpdatePanel.cs
Log:
Initial UpdatePanel implementation

Modified: trunk/mcs/class/System.Web.Extensions/System.Web.UI/ScriptManager.cs
===================================================================
--- trunk/mcs/class/System.Web.Extensions/System.Web.UI/ScriptManager.cs        
2007-06-19 14:08:25 UTC (rev 80156)
+++ trunk/mcs/class/System.Web.Extensions/System.Web.UI/ScriptManager.cs        
2007-06-19 14:15:55 UTC (rev 80157)
@@ -77,6 +77,7 @@
                int _asyncPostBackTimeout = 90;
                List<Control> _asyncPostBackControls;
                List<Control> _postBackControls;
+               List<UpdatePanel> _updatePanels;
                ScriptReferenceCollection _scripts;
                bool _isInAsyncPostBack;
                string _asyncPostBackSourceElementID;
@@ -518,6 +519,16 @@
                        _postBackControls.Add (control);
                }
 
+               internal void RegisterUpdatePanel (UpdatePanel updatePanel) {
+                       if (_updatePanels == null)
+                               _updatePanels = new List<UpdatePanel> ();
+
+                       if (_updatePanels.Contains (updatePanel))
+                               return;
+
+                       _updatePanels.Add (updatePanel);
+               }
+
                public void RegisterScriptDescriptors (IExtenderControl 
extenderControl)
                {
                        throw new NotImplementedException ();
@@ -547,12 +558,26 @@
                        writer.WriteLine ("<script type=\"text/javascript\">");
                        writer.WriteLine ("//<![CDATA[");
                        writer.WriteLine 
("Sys.WebForms.PageRequestManager._initialize('{0}', 
document.getElementById('{1}'));", UniqueID, Page.Form.ClientID);
-                       writer.WriteLine 
("Sys.WebForms.PageRequestManager.getInstance()._updateControls([{0}], [{1}], 
[{2}], {3});", null, FormatListIDs (_asyncPostBackControls), FormatListIDs 
(_postBackControls), AsyncPostBackTimeout);
+                       writer.WriteLine 
("Sys.WebForms.PageRequestManager.getInstance()._updateControls([{0}], [{1}], 
[{2}], {3});", FormatUpdatePanelIDs (_updatePanels), FormatListIDs 
(_asyncPostBackControls), FormatListIDs (_postBackControls), 
AsyncPostBackTimeout);
                        writer.WriteLine ("//]]");
                        writer.WriteLine ("</script>");
                        base.Render (writer);
                }
 
+               static string FormatUpdatePanelIDs (List<UpdatePanel> list) {
+                       if (list == null || list.Count == 0)
+                               return null;
+
+                       StringBuilder sb = new StringBuilder ();
+                       for (int i = 0; i < list.Count; i++) {
+                               sb.AppendFormat ("'{0}{1}',", list 
[i].ChildrenAsTriggers ? "t" : "f", list [i].UniqueID);
+                       }
+                       if (sb.Length > 0)
+                               sb.Length--;
+
+                       return sb.ToString ();
+               }
+
                static string FormatListIDs(List<Control> list)
                {
                        if (list == null || list.Count == 0)
@@ -604,7 +629,7 @@
                        Page page = (Page) container;
 
                        page.Form.SetRenderMethodDelegate (RenderFormCallback);
-                       HtmlTextParser parser = new HtmlTextParser ();
+                       HtmlTextParser parser = new HtmlTextParser (output);
                        page.Form.RenderControl (parser);
 
                        parser.WriteOutput (output);
@@ -612,6 +637,22 @@
                }
 
                void RenderFormCallback (HtmlTextWriter output, Control 
container) {
+                       output = ((HtmlTextParser) output).ResponseOutput;
+                       if (_updatePanels != null && _updatePanels.Count > 0) {
+                               StringBuilder sb = new StringBuilder ();
+                               HtmlTextWriter w = new HtmlTextWriter (new 
StringWriter (sb));
+                               for (int i = 0; i < _updatePanels.Count; i++) {
+                                       UpdatePanel panel = _updatePanels [i];
+                                       if (panel.RequiresUpdate) {
+                                               panel.RenderChildrenInternal 
(w);
+                                               w.Flush ();
+                                               string panelOutput = 
sb.ToString ();
+                                               sb.Length = 0;
+                                               WriteCallbackOutput (output, 
updatePanel, panel.ClientID, panelOutput);
+                                       }
+                               }
+                       }
+                       
                        HtmlForm form = (HtmlForm) container;
                        HtmlTextWriter writer = new HtmlTextWriter (new 
DropWriter ());
                        if (form.HasControls ()) {
@@ -623,11 +664,17 @@
 
                class HtmlTextParser : HtmlTextWriter
                {
-                       public HtmlTextParser ()
-                               : base (new TextParser ()) {
+                       HtmlTextWriter _responseOutput;
 
+                       public HtmlTextWriter ResponseOutput {
+                               get { return _responseOutput; }
                        }
 
+                       public HtmlTextParser (HtmlTextWriter responseOutput)
+                               : base (new TextParser ()) {
+                               _responseOutput = responseOutput;
+                       }
+
                        public void WriteOutput (HtmlTextWriter output) {
                                ((TextParser) InnerWriter).WriteOutput (output);
                        }

Modified: trunk/mcs/class/System.Web.Extensions/System.Web.UI/UpdatePanel.cs
===================================================================
--- trunk/mcs/class/System.Web.Extensions/System.Web.UI/UpdatePanel.cs  
2007-06-19 14:08:25 UTC (rev 80156)
+++ trunk/mcs/class/System.Web.Extensions/System.Web.UI/UpdatePanel.cs  
2007-06-19 14:15:55 UTC (rev 80157)
@@ -43,14 +43,20 @@
        [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, 
Level = AspNetHostingPermissionLevel.Minimal)]
        public class UpdatePanel : Control
        {
+               ITemplate _contentTemplate;
+               Control _contentTemplateContainer;
+               UpdatePanelUpdateMode _updateMode = 
UpdatePanelUpdateMode.Always;
+               bool _childrenAsTriggers = true;
+               bool _requiresUpdate = false;
+
                [Category ("Behavior")]
                [DefaultValue (true)]
                public bool ChildrenAsTriggers {
                        get {
-                               throw new NotImplementedException ();
+                               return _childrenAsTriggers;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               _childrenAsTriggers = value;
                        }
                }
 
@@ -59,17 +65,21 @@
                [Browsable (false)]
                public ITemplate ContentTemplate {
                        get {
-                               throw new NotImplementedException ();
+                               return _contentTemplate;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               _contentTemplate = value;
                        }
                }
 
                [Browsable (false)]
                public Control ContentTemplateContainer {
                        get {
-                               throw new NotImplementedException ();
+                               if (_contentTemplateContainer == null) {
+                                       _contentTemplateContainer = 
CreateContentTemplateContainer ();
+                                       Controls.Add 
(_contentTemplateContainer);
+                               }
+                               return _contentTemplateContainer;
                        }
                }
 
@@ -98,10 +108,19 @@
 
                protected internal virtual bool RequiresUpdate {
                        get {
-                               throw new NotImplementedException ();
+                               return UpdateMode == 
UpdatePanelUpdateMode.Always || _requiresUpdate;
                        }
                }
 
+               ScriptManager ScriptManager {
+                       get {
+                               ScriptManager manager = 
ScriptManager.GetCurrent (Page);
+                               if (manager == null)
+                                       throw new InvalidOperationException 
(String.Format ("The control with ID '{0}' requires a ScriptManager on the 
page. The ScriptManager must appear before any controls that need it.", ID));
+                               return manager;
+                       }
+               }
+
                [MergableProperty (false)]
                [DefaultValue ("")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
@@ -113,23 +132,33 @@
                }
 
                [Category ("Behavior")]
+               [DefaultValueAttribute(UpdatePanelUpdateMode.Always)]
                public UpdatePanelUpdateMode UpdateMode {
                        get {
-                               throw new NotImplementedException ();
+                               return _updateMode;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               _updateMode = value;
                        }
                }
 
                protected virtual Control CreateContentTemplateContainer ()
                {
-                       throw new NotImplementedException ();
+                       return new Control ();
                }
 
+               [MonoTODO()]
                protected override sealed ControlCollection 
CreateControlCollection ()
                {
-                       throw new NotImplementedException ();
+                       // TODO: Because this method is protected and sealed, 
it is visible to classes that inherit 
+                       // from the UpdatePanel class, but it cannot be 
overridden. This method overrides 
+                       // the base implementation to return a specialized 
ControlCollection object that throws 
+                       // an InvalidOperationException when the Add(Control), 
AddAt(Int32, Control), Clear(), 
+                       // Remove(Control), or RemoveAt(Int32) method of the 
ControlCollection class is invoked. 
+                       // To change the content of the UpdatePanel control, 
modify the child controls of 
+                       // the ContentTemplateContainer property.
+
+                       return base.CreateControlCollection();
                }
 
                protected internal virtual void Initialize ()
@@ -140,6 +169,11 @@
                protected override void OnInit (EventArgs e)
                {
                        base.OnInit (e);
+
+                       ScriptManager.RegisterUpdatePanel (this);
+
+                       if (ContentTemplate != null)
+                               ContentTemplate.InstantiateIn 
(ContentTemplateContainer);
                }
 
                protected override void OnLoad (EventArgs e)
@@ -150,6 +184,9 @@
                protected override void OnPreRender (EventArgs e)
                {
                        base.OnPreRender (e);
+
+                       if (UpdateMode == UpdatePanelUpdateMode.Always && 
!ChildrenAsTriggers)
+                               throw new InvalidOperationException 
(String.Format ("ChildrenAsTriggers cannot be set to false when UpdateMode is 
set to Always on UpdatePanel '{0}'", ID));
                }
 
                protected override void OnUnload (EventArgs e)
@@ -159,15 +196,26 @@
 
                protected override void Render (HtmlTextWriter writer)
                {
+                       writer.AddAttribute (HtmlTextWriterAttribute.Id, 
ClientID);
+                       writer.RenderBeginTag (HtmlTextWriterTag.Div);
+                       RenderChildren (writer);
+                       writer.RenderEndTag ();
                }
 
                protected override void RenderChildren (HtmlTextWriter writer)
                {
+                       if (ScriptManager.IsInAsyncPostBack)
+                               return;
+                       RenderChildrenInternal (writer);
                }
 
+               internal void RenderChildrenInternal (HtmlTextWriter writer) {
+                       base.RenderChildren (writer);
+               }
+
                public void Update ()
                {
-                       throw new NotImplementedException ();
+                       _requiresUpdate = true;
                }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to