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;
35 using System.Collections.Specialized;
36 using System.Collections;
37 using System.Web.Handlers;
38 using System.Reflection;
39 using System.Web.Configuration;
40 using System.Web.UI.HtmlControls;
42 using System.Globalization;
43 using System.Threading;
45 namespace System.Web.UI
47 [ParseChildrenAttribute (true)]
48 [DefaultPropertyAttribute ("Scripts")]
49 [DesignerAttribute ("System.Web.UI.Design.ScriptManagerDesigner, System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
50 [NonVisualControlAttribute]
51 [PersistChildrenAttribute (false)]
52 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
53 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
54 public class ScriptManager : Control, IPostBackDataHandler
56 // the keywords are used in fomatting async response
57 const string updatePanel = "updatePanel";
58 const string hiddenField = "hiddenField";
59 const string arrayDeclaration = "arrayDeclaration";
60 const string scriptBlock = "scriptBlock";
61 const string expando = "expando";
62 const string onSubmit = "onSubmit";
63 const string asyncPostBackControlIDs = "asyncPostBackControlIDs";
64 const string postBackControlIDs = "postBackControlIDs";
65 const string updatePanelIDs = "updatePanelIDs";
66 const string asyncPostBackTimeout = "asyncPostBackTimeout";
67 const string childUpdatePanelIDs = "childUpdatePanelIDs";
68 const string panelsToRefreshIDs = "panelsToRefreshIDs";
69 const string formAction = "formAction";
70 const string dataItem = "dataItem";
71 const string dataItemJson = "dataItemJson";
72 const string scriptDispose = "scriptDispose";
73 const string pageRedirect = "pageRedirect";
74 const string error = "error";
75 const string pageTitle = "pageTitle";
76 const string focus = "focus";
77 const string scriptContentNoTags = "ScriptContentNoTags";
78 const string scriptContentWithTags = "ScriptContentWithTags";
79 const string scriptPath = "ScriptPath";
81 int _asyncPostBackTimeout = 90;
82 List<Control> _asyncPostBackControls;
83 List<Control> _postBackControls;
84 List<UpdatePanel> _updatePanels;
85 ScriptReferenceCollection _scripts;
86 bool _isInAsyncPostBack;
87 string _asyncPostBackSourceElementID;
88 ScriptMode _scriptMode = ScriptMode.Auto;
89 bool _enableScriptGlobalization;
90 bool _enableScriptLocalization;
92 ScriptEntry _clientScriptBlocks;
93 ScriptEntry _startupScriptBlocks;
94 List<ArrayDeclaration> _arrayDeclarations;
95 Hashtable _hiddenFields;
98 [Category ("Behavior")]
99 public bool AllowCustomErrorsRedirect {
101 throw new NotImplementedException ();
104 throw new NotImplementedException ();
108 [Category ("Behavior")]
110 public string AsyncPostBackErrorMessage {
112 throw new NotImplementedException ();
115 throw new NotImplementedException ();
120 public string AsyncPostBackSourceElementID {
122 if(_asyncPostBackSourceElementID==null)
124 return _asyncPostBackSourceElementID;
129 [Category ("Behavior")]
130 public int AsyncPostBackTimeout {
132 return _asyncPostBackTimeout;
135 _asyncPostBackTimeout = value;
139 [Category ("Behavior")]
140 [MergableProperty (false)]
142 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
143 [PersistenceMode (PersistenceMode.InnerProperty)]
144 public AuthenticationServiceManager AuthenticationService {
146 throw new NotImplementedException ();
150 [Category ("Behavior")]
151 [DefaultValue (false)]
152 public bool EnablePageMethods {
154 throw new NotImplementedException ();
157 throw new NotImplementedException ();
161 [DefaultValue (true)]
162 [Category ("Behavior")]
163 public bool EnablePartialRendering {
165 throw new NotImplementedException ();
168 throw new NotImplementedException ();
172 [DefaultValue (false)]
173 [Category ("Behavior")]
174 public bool EnableScriptGlobalization {
176 return _enableScriptGlobalization;
179 _enableScriptGlobalization = value;
183 [Category ("Behavior")]
184 [DefaultValue (false)]
185 public bool EnableScriptLocalization {
187 return _enableScriptLocalization;
190 _enableScriptLocalization = value;
195 public bool IsDebuggingEnabled {
197 if (IsDeploymentRetail)
200 CompilationSection compilation = (CompilationSection) WebConfigurationManager.GetSection ("system.web/compilation");
201 if (!compilation.Debug && (ScriptMode == ScriptMode.Auto || ScriptMode == ScriptMode.Inherit))
204 if (ScriptMode == ScriptMode.Release)
211 bool IsDeploymentRetail {
213 DeploymentSection deployment = (DeploymentSection) WebConfigurationManager.GetSection ("system.web/deployment");
214 return deployment.Retail;
219 public bool IsInAsyncPostBack {
221 return _isInAsyncPostBack;
225 [Category ("Behavior")]
226 [DefaultValue (true)]
227 public bool LoadScriptsBeforeUI {
229 throw new NotImplementedException ();
232 throw new NotImplementedException ();
236 [PersistenceMode (PersistenceMode.InnerProperty)]
238 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
239 [Category ("Behavior")]
240 [MergableProperty (false)]
241 public ProfileServiceManager ProfileService {
243 throw new NotImplementedException ();
247 [Category ("Behavior")]
248 public ScriptMode ScriptMode {
253 if (value == ScriptMode.Inherit)
254 value = ScriptMode.Auto;
260 [Category ("Behavior")]
261 public string ScriptPath {
263 if (_scriptPath == null)
272 [PersistenceMode (PersistenceMode.InnerProperty)]
274 [Category ("Behavior")]
275 [MergableProperty (false)]
276 public ScriptReferenceCollection Scripts {
278 if (_scripts == null)
279 _scripts = new ScriptReferenceCollection ();
285 [PersistenceMode (PersistenceMode.InnerProperty)]
287 [MergableProperty (false)]
288 [Category ("Behavior")]
289 public ServiceReferenceCollection Services {
291 throw new NotImplementedException ();
295 [DefaultValue (true)]
297 public bool SupportsPartialRendering {
299 throw new NotImplementedException ();
302 throw new NotImplementedException ();
306 [EditorBrowsable (EditorBrowsableState.Never)]
308 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
309 public override bool Visible {
314 throw new NotImplementedException ();
318 [Category ("Action")]
319 public event EventHandler<AsyncPostBackErrorEventArgs> AsyncPostBackError;
321 [Category ("Action")]
322 public event EventHandler<ScriptReferenceEventArgs> ResolveScriptReference;
324 public static ScriptManager GetCurrent (Page page)
326 HttpContext ctx = HttpContext.Current;
330 return (ScriptManager) ctx.Items [page];
333 static void SetCurrent (Page page, ScriptManager instance) {
334 HttpContext ctx = HttpContext.Current;
335 ctx.Items [page] = instance;
338 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
340 _isInAsyncPostBack = true;
341 string arg = postCollection [postDataKey];
342 if (!String.IsNullOrEmpty (arg)) {
343 string [] args = arg.Split ('|');
344 Control c = Page.FindControl (args [0]);
345 UpdatePanel up = c as UpdatePanel;
346 if (up != null && up.ChildrenAsTriggers)
348 _asyncPostBackSourceElementID = args[1];
353 protected internal virtual void OnAsyncPostBackError (AsyncPostBackErrorEventArgs e)
355 if (AsyncPostBackError != null)
356 AsyncPostBackError (this, e);
359 protected override void OnInit (EventArgs e)
363 if (GetCurrent (Page) != null)
364 throw new InvalidOperationException ("Only one instance of a ScriptManager can be added to the page.");
366 SetCurrent (Page, this);
369 protected override void OnPreRender (EventArgs e)
371 base.OnPreRender (e);
373 if (IsInAsyncPostBack) {
374 Page.SetRenderMethodDelegate (RenderPageCallback);
377 if (EnableScriptGlobalization) {
378 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
379 string script = null; // TODO: Json serialization of culture
380 RegisterClientScriptBlock (this, typeof (ScriptManager), "ScriptGlobalization", script, true);
384 foreach (ScriptReference script in GetScriptReferences ()) {
385 OnResolveScriptReference (new ScriptReferenceEventArgs (script));
386 RegisterScriptReference (script);
389 // Register startup script
390 RegisterStartupScript (this, typeof (ScriptManager), "Sys.Application.initialize();", "Sys.Application.initialize();", true);
394 IEnumerable GetScriptReferences () {
395 ScriptReference script;
397 script = new ScriptReference ("MicrosoftAjax.js", String.Empty);
398 script.NotifyScriptLoaded = false;
401 script = new ScriptReference ("MicrosoftAjaxWebForms.js", String.Empty);
402 script.NotifyScriptLoaded = false;
405 if (_scripts != null && _scripts.Count > 0) {
406 for (int i = 0; i < _scripts.Count; i++) {
407 yield return _scripts [i];
412 protected virtual void OnResolveScriptReference (ScriptReferenceEventArgs e)
414 if (ResolveScriptReference != null)
415 ResolveScriptReference (this, e);
418 protected virtual void RaisePostDataChangedEvent ()
420 throw new NotImplementedException ();
423 public static void RegisterArrayDeclaration (Control control, string arrayName, string arrayValue)
425 RegisterArrayDeclaration (control.Page, arrayName, arrayValue);
428 public static void RegisterArrayDeclaration (Page page, string arrayName, string arrayValue)
430 ScriptManager sm = GetCurrent (page);
431 if (sm.IsInAsyncPostBack)
432 sm.RegisterArrayDeclaration (arrayName, arrayValue);
434 page.ClientScript.RegisterArrayDeclaration (arrayName, arrayValue);
437 void RegisterArrayDeclaration (string arrayName, string arrayValue) {
438 if (_arrayDeclarations == null)
439 _arrayDeclarations = new List<ArrayDeclaration> ();
441 _arrayDeclarations.Add(new ArrayDeclaration(arrayName, arrayValue));
444 public void RegisterAsyncPostBackControl (Control control)
449 if (_asyncPostBackControls == null)
450 _asyncPostBackControls = new List<Control> ();
452 if (_asyncPostBackControls.Contains (control))
455 _asyncPostBackControls.Add (control);
458 public static void RegisterClientScriptBlock (Control control, Type type, string key, string script, bool addScriptTags)
460 RegisterClientScriptBlock (control.Page, type, key, script, addScriptTags);
463 public static void RegisterClientScriptBlock (Page page, Type type, string key, string script, bool addScriptTags)
465 ScriptManager sm = GetCurrent (page);
466 if (sm.IsInAsyncPostBack)
467 RegisterScript (ref sm._clientScriptBlocks, type, key, script, addScriptTags ? ScriptEntryType.ScriptContentNoTags : ScriptEntryType.ScriptContentWithTags);
469 page.ClientScript.RegisterClientScriptBlock (type, key, script, addScriptTags);
472 public static void RegisterClientScriptInclude (Control control, Type type, string key, string url)
474 RegisterClientScriptInclude (control.Page, type, key, url);
477 public static void RegisterClientScriptInclude (Page page, Type type, string key, string url)
479 ScriptManager sm = GetCurrent (page);
480 if (sm.IsInAsyncPostBack)
481 RegisterScript (ref sm._clientScriptBlocks, type, key, url, ScriptEntryType.ScriptPath);
483 page.ClientScript.RegisterClientScriptInclude (type, key, url);
486 public static void RegisterClientScriptResource (Control control, Type type, string resourceName)
488 RegisterClientScriptResource (control.Page, type, resourceName);
491 public static void RegisterClientScriptResource (Page page, Type type, string resourceName)
493 RegisterClientScriptInclude (page, type, "resource-" + resourceName, ScriptResourceHandler.GetResourceUrl (type, resourceName));
496 void RegisterScriptReference (ScriptReference script) {
498 bool isDebugMode = IsDeploymentRetail ? false : (script.ScriptModeInternal == ScriptMode.Inherit ? IsDebuggingEnabled : (script.ScriptModeInternal == ScriptMode.Debug));
500 if (!String.IsNullOrEmpty (script.Path)) {
501 url = GetScriptName (ResolveClientUrl (script.Path), isDebugMode, EnableScriptLocalization ? script.ResourceUICultures : null);
503 else if (!String.IsNullOrEmpty (script.Name)) {
505 if (String.IsNullOrEmpty (script.Assembly))
506 assembly = typeof (ScriptManager).Assembly;
508 assembly = Assembly.Load (script.Assembly);
509 string name = GetScriptName (script.Name, isDebugMode, null);
510 if (script.IgnoreScriptPath || String.IsNullOrEmpty (ScriptPath))
511 url = ScriptResourceHandler.GetResourceUrl (assembly, name, script.NotifyScriptLoaded);
513 AssemblyName an = assembly.GetName ();
514 url = ResolveClientUrl (String.Concat (VirtualPathUtility.AppendTrailingSlash (ScriptPath), an.Name, '/', an.Version, '/', name));
518 throw new InvalidOperationException ("Name and Path cannot both be empty.");
521 RegisterClientScriptInclude (this, typeof (ScriptManager), url, url);
524 static string GetScriptName (string releaseName, bool isDebugMode, string [] supportedUICultures) {
525 if (!isDebugMode && (supportedUICultures == null || supportedUICultures.Length == 0))
528 if (releaseName.Length < 3 || !releaseName.EndsWith (".js", StringComparison.OrdinalIgnoreCase))
529 throw new InvalidOperationException (String.Format ("'{0}' is not a valid script path. The path must end in '.js'.", releaseName));
531 StringBuilder sb = new StringBuilder (releaseName);
534 sb.Append (".debug");
535 string culture=Thread.CurrentThread.CurrentUICulture.Name;
536 if (supportedUICultures != null && Array.IndexOf<string> (supportedUICultures, culture) >= 0)
537 sb.AppendFormat (".{0}", culture);
540 return sb.ToString ();
543 public void RegisterDataItem (Control control, string dataItem)
545 throw new NotImplementedException ();
548 public void RegisterDataItem (Control control, string dataItem, bool isJsonSerialized)
550 throw new NotImplementedException ();
553 public void RegisterDispose (Control control, string disposeScript)
555 throw new NotImplementedException ();
558 public static void RegisterExpandoAttribute (Control control, string controlId, string attributeName, string attributeValue, bool encode)
560 throw new NotImplementedException ();
563 public static void RegisterHiddenField (Control control, string hiddenFieldName, string hiddenFieldInitialValue)
565 RegisterHiddenField (control.Page, hiddenFieldName, hiddenFieldInitialValue);
568 public static void RegisterHiddenField (Page page, string hiddenFieldName, string hiddenFieldInitialValue)
570 ScriptManager sm = GetCurrent (page);
571 if (sm.IsInAsyncPostBack)
572 sm.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
574 page.ClientScript.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
577 void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue) {
578 if (_hiddenFields == null)
579 _hiddenFields = new Hashtable ();
581 if (!_hiddenFields.ContainsKey (hiddenFieldName))
582 _hiddenFields.Add (hiddenFieldName, hiddenFieldInitialValue);
585 public static void RegisterOnSubmitStatement (Control control, Type type, string key, string script)
587 throw new NotImplementedException ();
590 public static void RegisterOnSubmitStatement (Page page, Type type, string key, string script)
592 throw new NotImplementedException ();
595 public void RegisterPostBackControl (Control control)
600 if (_postBackControls == null)
601 _postBackControls = new List<Control> ();
603 if (_postBackControls.Contains (control))
606 _postBackControls.Add (control);
609 internal void RegisterUpdatePanel (UpdatePanel updatePanel) {
610 if (_updatePanels == null)
611 _updatePanels = new List<UpdatePanel> ();
613 if (_updatePanels.Contains (updatePanel))
616 _updatePanels.Add (updatePanel);
619 public void RegisterScriptDescriptors (IExtenderControl extenderControl)
621 throw new NotImplementedException ();
624 public void RegisterScriptDescriptors (IScriptControl scriptControl)
626 throw new NotImplementedException ();
629 public static void RegisterStartupScript (Control control, Type type, string key, string script, bool addScriptTags)
631 RegisterStartupScript (control.Page, type, key, script, addScriptTags);
634 public static void RegisterStartupScript (Page page, Type type, string key, string script, bool addScriptTags)
636 ScriptManager sm = GetCurrent (page);
637 if (sm.IsInAsyncPostBack)
638 RegisterScript (ref sm._startupScriptBlocks, type, key, script, addScriptTags ? ScriptEntryType.ScriptContentNoTags : ScriptEntryType.ScriptContentWithTags);
640 page.ClientScript.RegisterStartupScript (type, key, script, addScriptTags);
643 static void RegisterScript (ref ScriptEntry scriptList, Type type, string key, string script, ScriptEntryType scriptEntryType) {
644 ScriptEntry last = null;
645 ScriptEntry entry = scriptList;
647 while (entry != null) {
648 if (entry.Type == type && entry.Key == key)
654 entry = new ScriptEntry (type, key, script, scriptEntryType);
662 protected override void Render (HtmlTextWriter writer)
664 // MSDN: This method is used by control developers to extend the ScriptManager control.
665 // Notes to Inheritors:
666 // When overriding this method, call the base Render(HtmlTextWriter) method
667 // so that PageRequestManager is rendered on the page.
668 writer.WriteLine ("<script type=\"text/javascript\">");
669 writer.WriteLine ("//<![CDATA[");
670 writer.WriteLine ("Sys.WebForms.PageRequestManager._initialize('{0}', document.getElementById('{1}'));", UniqueID, Page.Form.ClientID);
671 writer.WriteLine ("Sys.WebForms.PageRequestManager.getInstance()._updateControls([{0}], [{1}], [{2}], {3});", FormatUpdatePanelIDs (_updatePanels, true), FormatListIDs (_asyncPostBackControls, true), FormatListIDs (_postBackControls, true), AsyncPostBackTimeout);
672 writer.WriteLine ("//]]");
673 writer.WriteLine ("</script>");
674 base.Render (writer);
677 static string FormatUpdatePanelIDs (List<UpdatePanel> list, bool useSingleQuote) {
678 if (list == null || list.Count == 0)
681 StringBuilder sb = new StringBuilder ();
682 for (int i = 0; i < list.Count; i++) {
683 sb.AppendFormat ("{0}{1}{2}{0},", useSingleQuote ? "'" : String.Empty, list [i].ChildrenAsTriggers ? "t" : "f", list [i].UniqueID);
688 return sb.ToString ();
691 static string FormatListIDs (List<Control> list, bool useSingleQuote)
693 if (list == null || list.Count == 0)
696 StringBuilder sb = new StringBuilder ();
697 for (int i = 0; i < list.Count; i++) {
698 sb.AppendFormat ("{0}{1}{0},", useSingleQuote ? "'" : String.Empty, list [i].UniqueID);
703 return sb.ToString ();
706 public void SetFocus (Control control)
708 throw new NotImplementedException ();
711 public void SetFocus (string clientID)
713 throw new NotImplementedException ();
716 #region IPostBackDataHandler Members
718 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
720 return LoadPostData (postDataKey, postCollection);
723 void IPostBackDataHandler.RaisePostDataChangedEvent ()
725 RaisePostDataChangedEvent ();
730 static internal void WriteCallbackException (TextWriter output, Exception ex) {
731 HttpException httpEx = ex as HttpException;
732 WriteCallbackOutput (output, error, httpEx == null ? "500" : httpEx.GetHttpCode ().ToString (), ex.GetBaseException ().Message);
735 static internal void WriteCallbackRedirect (TextWriter output, string redirectUrl) {
736 WriteCallbackOutput (output, pageRedirect, null, redirectUrl);
739 static void WriteCallbackOutput (TextWriter output, string type, string name, string value) {
740 output.Write ("{0}|{1}|{2}|{3}|", value == null ? 0 : value.Length, type, name, value);
743 void RenderPageCallback (HtmlTextWriter output, Control container) {
744 Page page = (Page) container;
746 page.Form.SetRenderMethodDelegate (RenderFormCallback);
747 HtmlTextParser parser = new HtmlTextParser (output);
748 page.Form.RenderControl (parser);
750 parser.WriteOutput (output);
751 WriteCallbackOutput (output, asyncPostBackControlIDs, null, FormatListIDs (_asyncPostBackControls, false));
752 WriteCallbackOutput (output, postBackControlIDs, null, FormatListIDs (_postBackControls, false));
753 WriteCallbackOutput (output, updatePanelIDs, null, FormatUpdatePanelIDs (_updatePanels, false));
754 WriteCallbackOutput (output, asyncPostBackTimeout, null, AsyncPostBackTimeout.ToString ());
755 WriteCallbackOutput (output, pageTitle, null, Page.Title);
757 WriteArrayDeclarations (output);
758 WriteScriptBlocks (output, _clientScriptBlocks);
759 WriteScriptBlocks (output, _startupScriptBlocks);
760 WriteHiddenFields (output);
763 void WriteArrayDeclarations (HtmlTextWriter writer) {
764 if (_arrayDeclarations != null) {
765 for (int i = 0; i < _arrayDeclarations.Count; i++) {
766 ArrayDeclaration array = _arrayDeclarations [i];
767 WriteCallbackOutput (writer, arrayDeclaration, array.ArrayName, array.ArrayValue);
772 void WriteScriptBlocks (HtmlTextWriter output, ScriptEntry scriptList) {
773 while (scriptList != null) {
774 switch (scriptList.ScriptEntryType) {
775 case ScriptEntryType.ScriptContentNoTags:
776 WriteCallbackOutput (output, scriptBlock, scriptContentNoTags, scriptList.Script);
778 case ScriptEntryType.ScriptContentWithTags:
779 string script = SerializeScriptBlock (scriptList);
780 WriteCallbackOutput (output, scriptBlock, scriptContentWithTags, script);
782 case ScriptEntryType.ScriptPath:
783 WriteCallbackOutput (output, scriptBlock, scriptPath, scriptList.Script);
786 scriptList = scriptList.Next;
790 void WriteHiddenFields (HtmlTextWriter output) {
791 if (_hiddenFields == null)
793 foreach (string key in _hiddenFields.Keys) {
794 string value = _hiddenFields [key] as string;
795 WriteCallbackOutput (output, hiddenField, key, value);
800 static string SerializeScriptBlock (ScriptEntry scriptList) {
801 throw new InvalidOperationException (String.Format ("The script tag registered for type '{0}' and key '{1}' has invalid characters outside of the script tags: {2}. Only properly formatted script tags can be registered.", scriptList.Type, scriptList.Key, scriptList.Script));
804 void RenderFormCallback (HtmlTextWriter output, Control container) {
805 output = ((HtmlTextParser) output).ResponseOutput;
806 if (_updatePanels != null && _updatePanels.Count > 0) {
807 StringBuilder sb = new StringBuilder ();
808 HtmlTextWriter w = new HtmlTextWriter (new StringWriter (sb));
809 for (int i = 0; i < _updatePanels.Count; i++) {
810 UpdatePanel panel = _updatePanels [i];
812 panel.RenderChildrenInternal (w);
814 if (panel.RequiresUpdate) {
815 string panelOutput = sb.ToString ();
816 WriteCallbackOutput (output, updatePanel, panel.ClientID, panelOutput);
823 HtmlForm form = (HtmlForm) container;
824 HtmlTextWriter writer = new HtmlTextWriter (new DropWriter ());
825 if (form.HasControls ()) {
826 for (int i = 0; i < form.Controls.Count; i++) {
827 form.Controls [i].RenderControl (writer);
832 sealed class HtmlTextParser : HtmlTextWriter
834 readonly HtmlTextWriter _responseOutput;
836 public HtmlTextWriter ResponseOutput {
837 get { return _responseOutput; }
840 public HtmlTextParser (HtmlTextWriter responseOutput)
841 : base (new TextParser ()) {
842 _responseOutput = responseOutput;
845 public void WriteOutput (HtmlTextWriter output) {
846 ((TextParser) InnerWriter).WriteOutput (output);
850 sealed class TextParser : TextWriter
853 char _charState = (char) 255;
854 const char nullCharState = (char) 255;
855 StringBuilder _sb = new StringBuilder ();
856 List<Hashtable> _hiddenFields;
857 Hashtable _currentField;
858 string _currentAttribute;
860 public override Encoding Encoding {
861 get { return Encoding.UTF8; }
864 public override void Write (char value) {
867 ParseBeginTag (value);
870 ParseAttributeName (value);
873 ParseAttributeValue (value);
878 private void ParseAttributeValue (char value) {
884 _currentField [_currentAttribute] = _sb.ToString ();
894 private void ParseAttributeName (char value) {
903 _currentAttribute = _sb.ToString ();
913 void ParseBeginTag (char value) {
914 switch (_charState) {
952 _currentField = new Hashtable ();
953 if (_hiddenFields == null)
954 _hiddenFields = new List<Hashtable> ();
955 _hiddenFields.Add (_currentField);
963 private void ResetState () {
964 _charState = nullCharState;
969 public void WriteOutput (HtmlTextWriter output) {
970 if (_hiddenFields == null)
973 for (int i = 0; i < _hiddenFields.Count; i++) {
974 Hashtable field = _hiddenFields [i];
976 string value = (string) field ["value"];
977 if (String.IsNullOrEmpty (value))
980 ScriptManager.WriteCallbackOutput (output, ScriptManager.hiddenField, (string) field ["name"], value);
985 sealed class DropWriter : TextWriter
987 public override Encoding Encoding {
988 get { return Encoding.UTF8; }
992 sealed class ScriptEntry
994 readonly public Type Type;
995 readonly public string Key;
996 readonly public string Script;
997 readonly public ScriptEntryType ScriptEntryType;
998 public ScriptEntry Next;
1000 public ScriptEntry (Type type, string key, string script, ScriptEntryType scriptEntryType) {
1004 ScriptEntryType = scriptEntryType;
1008 enum ScriptEntryType
1010 ScriptContentNoTags,
1011 ScriptContentWithTags,
1015 sealed class ArrayDeclaration
1017 readonly public string ArrayName;
1018 readonly public string ArrayValue;
1020 public ArrayDeclaration (string arrayName, string arrayValue) {
1021 ArrayName = arrayName;
1022 ArrayValue = arrayValue;