5 // Igor Zelmanovich <igorz@mainsoft.com>
7 // (C) 2007 Mainsoft, Inc. http://www.mainsoft.com
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections.Generic;
33 using System.ComponentModel;
34 using System.Security.Permissions;
36 namespace System.Web.UI
38 [DesignerAttribute ("System.Web.UI.Design.UpdatePanelDesigner, System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
39 [DefaultPropertyAttribute ("Triggers")]
40 [ParseChildrenAttribute (true)]
41 [PersistChildrenAttribute (false)]
42 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
43 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
44 public class UpdatePanel : Control
46 ITemplate _contentTemplate;
47 Control _contentTemplateContainer;
48 UpdatePanelUpdateMode _updateMode = UpdatePanelUpdateMode.Always;
49 bool _childrenAsTriggers = true;
50 bool _requiresUpdate = false;
51 UpdatePanelTriggerCollection _triggers;
53 [Category ("Behavior")]
55 public bool ChildrenAsTriggers {
57 return _childrenAsTriggers;
60 _childrenAsTriggers = value;
64 [TemplateInstance (TemplateInstance.Single)]
65 [PersistenceMode (PersistenceMode.InnerProperty)]
67 public ITemplate ContentTemplate {
69 return _contentTemplate;
72 _contentTemplate = value;
77 public Control ContentTemplateContainer {
79 if (_contentTemplateContainer == null) {
80 _contentTemplateContainer = CreateContentTemplateContainer ();
81 Controls.Add (_contentTemplateContainer);
83 return _contentTemplateContainer;
87 public override sealed ControlCollection Controls {
94 public bool IsInPartialRendering {
96 throw new NotImplementedException ();
100 [Category ("Layout")]
101 public UpdatePanelRenderMode RenderMode {
103 throw new NotImplementedException ();
106 throw new NotImplementedException ();
110 protected internal virtual bool RequiresUpdate {
112 return UpdateMode == UpdatePanelUpdateMode.Always || _requiresUpdate;
116 internal ScriptManager ScriptManager {
118 ScriptManager manager = ScriptManager.GetCurrent (Page);
120 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));
125 [MergableProperty (false)]
127 [PersistenceMode (PersistenceMode.InnerProperty)]
128 [Category ("Behavior")]
129 public UpdatePanelTriggerCollection Triggers {
131 if (_triggers == null)
132 _triggers = new UpdatePanelTriggerCollection (this);
137 [Category ("Behavior")]
138 [DefaultValueAttribute(UpdatePanelUpdateMode.Always)]
139 public UpdatePanelUpdateMode UpdateMode {
148 protected virtual Control CreateContentTemplateContainer ()
150 return new Control ();
154 protected override sealed ControlCollection CreateControlCollection ()
156 // TODO: Because this method is protected and sealed, it is visible to classes that inherit
157 // from the UpdatePanel class, but it cannot be overridden. This method overrides
158 // the base implementation to return a specialized ControlCollection object that throws
159 // an InvalidOperationException when the Add(Control), AddAt(Int32, Control), Clear(),
160 // Remove(Control), or RemoveAt(Int32) method of the ControlCollection class is invoked.
161 // To change the content of the UpdatePanel control, modify the child controls of
162 // the ContentTemplateContainer property.
164 return base.CreateControlCollection();
167 protected internal virtual void Initialize ()
169 if (_triggers != null) {
170 for (int i = 0; i < _triggers.Count; i++) {
171 _triggers [i].Initialize ();
176 protected override void OnInit (EventArgs e)
180 ScriptManager.RegisterUpdatePanel (this);
182 if (ContentTemplate != null)
183 ContentTemplate.InstantiateIn (ContentTemplateContainer);
186 protected override void OnLoad (EventArgs e)
193 protected override void OnPreRender (EventArgs e)
195 base.OnPreRender (e);
197 if (UpdateMode == UpdatePanelUpdateMode.Always && !ChildrenAsTriggers)
198 throw new InvalidOperationException (String.Format ("ChildrenAsTriggers cannot be set to false when UpdateMode is set to Always on UpdatePanel '{0}'", ID));
201 protected override void OnUnload (EventArgs e)
206 protected override void Render (HtmlTextWriter writer)
208 writer.AddAttribute (HtmlTextWriterAttribute.Id, ClientID);
209 writer.RenderBeginTag (HtmlTextWriterTag.Div);
210 RenderChildren (writer);
211 writer.RenderEndTag ();
214 protected override void RenderChildren (HtmlTextWriter writer)
216 if (ScriptManager.IsInAsyncPostBack)
218 RenderChildrenInternal (writer);
221 internal void RenderChildrenInternal (HtmlTextWriter writer) {
222 base.RenderChildren (writer);
225 public void Update ()
227 _requiresUpdate = true;