ScriptManager.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  1. //
  2. // ScriptManager.cs
  3. //
  4. // Author:
  5. // Igor Zelmanovich <[email protected]>
  6. //
  7. // (C) 2007 Mainsoft, Inc. http://www.mainsoft.com
  8. //
  9. //
  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:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  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.
  28. //
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Text;
  32. using System.ComponentModel;
  33. using System.Security.Permissions;
  34. using System.Collections.Specialized;
  35. using System.Collections;
  36. using System.Web.Handlers;
  37. using System.Reflection;
  38. using System.Web.Configuration;
  39. using System.Web.UI.HtmlControls;
  40. using System.IO;
  41. using System.Globalization;
  42. using System.Threading;
  43. using System.Web.Script.Serialization;
  44. using System.Web.Script.Services;
  45. namespace System.Web.UI
  46. {
  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
  55. {
  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";
  80. static JavaScriptSerializer _cultureInfoSerializer;
  81. int _asyncPostBackTimeout = 90;
  82. List<Control> _asyncPostBackControls;
  83. List<Control> _postBackControls;
  84. List<UpdatePanel> _childUpdatePanels;
  85. List<UpdatePanel> _panelsToRefresh;
  86. List<UpdatePanel> _updatePanels;
  87. ScriptReferenceCollection _scripts;
  88. bool _isInAsyncPostBack;
  89. bool _isInPartialRendering;
  90. string _asyncPostBackSourceElementID;
  91. ScriptMode _scriptMode = ScriptMode.Auto;
  92. bool _enableScriptGlobalization;
  93. bool _enableScriptLocalization;
  94. string _scriptPath;
  95. ScriptEntry _clientScriptBlocks;
  96. ScriptEntry _startupScriptBlocks;
  97. ScriptEntry _scriptIncludes;
  98. ScriptEntry _onSubmitStatements;
  99. List<ArrayDeclaration> _arrayDeclarations;
  100. Hashtable _hiddenFields;
  101. List<IScriptControl> _registeredScriptControls;
  102. Dictionary<IExtenderControl, Control> _registeredExtenderControls;
  103. bool? _supportsPartialRendering;
  104. bool _enablePartialRendering = true;
  105. bool _init;
  106. string _panelToRefreshID;
  107. Dictionary<Control, DataItemEntry> _dataItems;
  108. bool _enablePageMethods;
  109. [DefaultValue (true)]
  110. [Category ("Behavior")]
  111. public bool AllowCustomErrorsRedirect {
  112. get {
  113. throw new NotImplementedException ();
  114. }
  115. set {
  116. throw new NotImplementedException ();
  117. }
  118. }
  119. [Category ("Behavior")]
  120. [DefaultValue ("")]
  121. public string AsyncPostBackErrorMessage {
  122. get {
  123. throw new NotImplementedException ();
  124. }
  125. set {
  126. throw new NotImplementedException ();
  127. }
  128. }
  129. [Browsable (false)]
  130. public string AsyncPostBackSourceElementID {
  131. get {
  132. if (_asyncPostBackSourceElementID == null)
  133. return String.Empty;
  134. return _asyncPostBackSourceElementID;
  135. }
  136. }
  137. [DefaultValue (90)]
  138. [Category ("Behavior")]
  139. public int AsyncPostBackTimeout {
  140. get {
  141. return _asyncPostBackTimeout;
  142. }
  143. set {
  144. _asyncPostBackTimeout = value;
  145. }
  146. }
  147. [Category ("Behavior")]
  148. [MergableProperty (false)]
  149. [DefaultValue ("")]
  150. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  151. [PersistenceMode (PersistenceMode.InnerProperty)]
  152. public AuthenticationServiceManager AuthenticationService {
  153. get {
  154. throw new NotImplementedException ();
  155. }
  156. }
  157. [Category ("Behavior")]
  158. [DefaultValue (false)]
  159. public bool EnablePageMethods {
  160. get {
  161. return _enablePageMethods;
  162. }
  163. set {
  164. _enablePageMethods = value;
  165. }
  166. }
  167. [DefaultValue (true)]
  168. [Category ("Behavior")]
  169. public bool EnablePartialRendering {
  170. get {
  171. return _enablePartialRendering;
  172. }
  173. set {
  174. if (_init)
  175. throw new InvalidOperationException ();
  176. _enablePartialRendering = value;
  177. }
  178. }
  179. [DefaultValue (false)]
  180. [Category ("Behavior")]
  181. public bool EnableScriptGlobalization {
  182. get {
  183. return _enableScriptGlobalization;
  184. }
  185. set {
  186. _enableScriptGlobalization = value;
  187. }
  188. }
  189. [Category ("Behavior")]
  190. [DefaultValue (false)]
  191. public bool EnableScriptLocalization {
  192. get {
  193. return _enableScriptLocalization;
  194. }
  195. set {
  196. _enableScriptLocalization = value;
  197. }
  198. }
  199. [Browsable (false)]
  200. public bool IsDebuggingEnabled {
  201. get {
  202. if (IsDeploymentRetail)
  203. return false;
  204. CompilationSection compilation = (CompilationSection) WebConfigurationManager.GetSection ("system.web/compilation");
  205. if (!compilation.Debug && (ScriptMode == ScriptMode.Auto || ScriptMode == ScriptMode.Inherit))
  206. return false;
  207. if (ScriptMode == ScriptMode.Release)
  208. return false;
  209. return true;
  210. }
  211. }
  212. bool IsDeploymentRetail {
  213. get {
  214. DeploymentSection deployment = (DeploymentSection) WebConfigurationManager.GetSection ("system.web/deployment");
  215. return deployment.Retail;
  216. }
  217. }
  218. [Browsable (false)]
  219. public bool IsInAsyncPostBack {
  220. get {
  221. return _isInAsyncPostBack;
  222. }
  223. }
  224. internal bool IsInPartialRendering {
  225. get {
  226. return _isInPartialRendering;
  227. }
  228. set {
  229. _isInPartialRendering = value;
  230. }
  231. }
  232. [Category ("Behavior")]
  233. [DefaultValue (true)]
  234. public bool LoadScriptsBeforeUI {
  235. get {
  236. throw new NotImplementedException ();
  237. }
  238. set {
  239. throw new NotImplementedException ();
  240. }
  241. }
  242. [PersistenceMode (PersistenceMode.InnerProperty)]
  243. [DefaultValue ("")]
  244. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  245. [Category ("Behavior")]
  246. [MergableProperty (false)]
  247. public ProfileServiceManager ProfileService {
  248. get {
  249. throw new NotImplementedException ();
  250. }
  251. }
  252. [Category ("Behavior")]
  253. public ScriptMode ScriptMode {
  254. get {
  255. return _scriptMode;
  256. }
  257. set {
  258. if (value == ScriptMode.Inherit)
  259. value = ScriptMode.Auto;
  260. _scriptMode = value;
  261. }
  262. }
  263. [DefaultValue ("")]
  264. [Category ("Behavior")]
  265. public string ScriptPath {
  266. get {
  267. if (_scriptPath == null)
  268. return String.Empty;
  269. return _scriptPath;
  270. }
  271. set {
  272. _scriptPath = value;
  273. }
  274. }
  275. [PersistenceMode (PersistenceMode.InnerProperty)]
  276. [DefaultValue ("")]
  277. [Category ("Behavior")]
  278. [MergableProperty (false)]
  279. public ScriptReferenceCollection Scripts {
  280. get {
  281. if (_scripts == null)
  282. _scripts = new ScriptReferenceCollection ();
  283. return _scripts;
  284. }
  285. }
  286. [PersistenceMode (PersistenceMode.InnerProperty)]
  287. [DefaultValue ("")]
  288. [MergableProperty (false)]
  289. [Category ("Behavior")]
  290. public ServiceReferenceCollection Services {
  291. get {
  292. throw new NotImplementedException ();
  293. }
  294. }
  295. [DefaultValue (true)]
  296. [Browsable (false)]
  297. public bool SupportsPartialRendering {
  298. get {
  299. if (!_supportsPartialRendering.HasValue)
  300. _supportsPartialRendering = CheckSupportsPartialRendering ();
  301. return _supportsPartialRendering.Value;
  302. }
  303. set {
  304. if (_init)
  305. throw new InvalidOperationException ();
  306. if (!EnablePartialRendering && value)
  307. throw new InvalidOperationException ("The SupportsPartialRendering property cannot be set when EnablePartialRendering is false.");
  308. _supportsPartialRendering = value;
  309. }
  310. }
  311. bool CheckSupportsPartialRendering () {
  312. if (!EnablePartialRendering)
  313. return false;
  314. // TODO: consider browser capabilities
  315. return true;
  316. }
  317. [EditorBrowsable (EditorBrowsableState.Never)]
  318. [Browsable (false)]
  319. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  320. public override bool Visible {
  321. get {
  322. return true;
  323. }
  324. set {
  325. throw new NotImplementedException ();
  326. }
  327. }
  328. [Category ("Action")]
  329. public event EventHandler<AsyncPostBackErrorEventArgs> AsyncPostBackError;
  330. [Category ("Action")]
  331. public event EventHandler<ScriptReferenceEventArgs> ResolveScriptReference;
  332. static ScriptManager () {
  333. _cultureInfoSerializer = new JavaScriptSerializer ();
  334. _cultureInfoSerializer.RegisterConverters (CultureInfoConverter.GetConverters ());
  335. }
  336. public static ScriptManager GetCurrent (Page page) {
  337. HttpContext ctx = HttpContext.Current;
  338. if (ctx == null)
  339. return null;
  340. return (ScriptManager) ctx.Items [page];
  341. }
  342. static void SetCurrent (Page page, ScriptManager instance) {
  343. HttpContext ctx = HttpContext.Current;
  344. ctx.Items [page] = instance;
  345. }
  346. protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection) {
  347. _isInAsyncPostBack = true;
  348. string arg = postCollection [postDataKey];
  349. if (!String.IsNullOrEmpty (arg)) {
  350. string [] args = arg.Split ('|');
  351. _panelToRefreshID = args [0];
  352. _asyncPostBackSourceElementID = args [1];
  353. return true;
  354. }
  355. return false;
  356. }
  357. protected internal virtual void OnAsyncPostBackError (AsyncPostBackErrorEventArgs e) {
  358. if (AsyncPostBackError != null)
  359. AsyncPostBackError (this, e);
  360. }
  361. protected override void OnInit (EventArgs e) {
  362. base.OnInit (e);
  363. if (GetCurrent (Page) != null)
  364. throw new InvalidOperationException ("Only one instance of a ScriptManager can be added to the page.");
  365. SetCurrent (Page, this);
  366. _init = true;
  367. }
  368. protected override void OnPreRender (EventArgs e) {
  369. base.OnPreRender (e);
  370. Page.PreRenderComplete += new EventHandler (OnPreRenderComplete);
  371. if (IsInAsyncPostBack) {
  372. Page.SetRenderMethodDelegate (RenderPageCallback);
  373. }
  374. else {
  375. if (EnableScriptGlobalization) {
  376. CultureInfo culture = Thread.CurrentThread.CurrentCulture;
  377. string script = String.Format ("var __cultureInfo = '{0}';", _cultureInfoSerializer.Serialize (culture));
  378. RegisterClientScriptBlock (this, typeof (ScriptManager), "ScriptGlobalization", script, true);
  379. }
  380. if (EnablePageMethods) {
  381. LogicalTypeInfo logicalTypeInfo = LogicalTypeInfo.GetLogicalTypeInfo (Page.GetType (), Page.Request.FilePath);
  382. RegisterStartupScript (this, typeof (ScriptManager), "PageMethods", logicalTypeInfo.Proxy, true);
  383. }
  384. // Register startup script
  385. StringBuilder sb = new StringBuilder ();
  386. sb.AppendLine ();
  387. sb.AppendLine ("Sys.Application.initialize();");
  388. RegisterStartupScript (this, typeof (ExtenderControl), "Sys.Application.initialize();", sb.ToString (), true);
  389. }
  390. }
  391. void OnPreRenderComplete (object sender, EventArgs e) {
  392. // Register Scripts
  393. List<ScriptReferenceEntry> scripts = new List<ScriptReferenceEntry> ();
  394. foreach (ScriptReferenceEntry script in GetScriptReferences ()) {
  395. OnResolveScriptReference (new ScriptReferenceEventArgs (script.ScriptReference));
  396. scripts.Add (script);
  397. }
  398. for (int i = 0; i < scripts.Count; i++)
  399. if (!IsInAsyncPostBack || HasBeenRendered (scripts [i].Control))
  400. RegisterScriptReference (scripts [i].ScriptReference);
  401. }
  402. static bool HasBeenRendered (Control control) {
  403. if(control==null)
  404. return false;
  405. UpdatePanel parent = control.Parent as UpdatePanel;
  406. if (parent != null && parent.RequiresUpdate)
  407. return true;
  408. return HasBeenRendered (control.Parent);
  409. }
  410. IEnumerable<ScriptReferenceEntry> GetScriptReferences () {
  411. ScriptReference script;
  412. script = new ScriptReference ("MicrosoftAjax.js", String.Empty);
  413. script.NotifyScriptLoaded = false;
  414. yield return new ScriptReferenceEntry (this, script);
  415. script = new ScriptReference ("MicrosoftAjaxWebForms.js", String.Empty);
  416. script.NotifyScriptLoaded = false;
  417. yield return new ScriptReferenceEntry (this, script);
  418. if (_scripts != null && _scripts.Count > 0) {
  419. for (int i = 0; i < _scripts.Count; i++) {
  420. yield return new ScriptReferenceEntry (this, _scripts [i]);
  421. }
  422. }
  423. if (_registeredScriptControls != null && _registeredScriptControls.Count > 0) {
  424. for (int i = 0; i < _registeredScriptControls.Count; i++) {
  425. IEnumerable<ScriptReference> scripts = _registeredScriptControls [i].GetScriptReferences ();
  426. if (scripts != null)
  427. foreach (ScriptReference s in scripts)
  428. yield return new ScriptReferenceEntry ((Control) _registeredScriptControls [i], s);
  429. }
  430. }
  431. if (_registeredExtenderControls != null && _registeredExtenderControls.Count > 0) {
  432. foreach (IExtenderControl ex in _registeredExtenderControls.Keys) {
  433. IEnumerable<ScriptReference> scripts = ex.GetScriptReferences ();
  434. if (scripts != null)
  435. foreach (ScriptReference s in scripts)
  436. yield return new ScriptReferenceEntry ((Control) ex, s);
  437. }
  438. }
  439. }
  440. protected virtual void OnResolveScriptReference (ScriptReferenceEventArgs e) {
  441. if (ResolveScriptReference != null)
  442. ResolveScriptReference (this, e);
  443. }
  444. protected virtual void RaisePostDataChangedEvent () {
  445. UpdatePanel up = Page.FindControl (_panelToRefreshID) as UpdatePanel;
  446. if (up != null && up.ChildrenAsTriggers)
  447. up.Update ();
  448. }
  449. public static void RegisterArrayDeclaration (Control control, string arrayName, string arrayValue) {
  450. RegisterArrayDeclaration (control.Page, arrayName, arrayValue);
  451. }
  452. public static void RegisterArrayDeclaration (Page page, string arrayName, string arrayValue) {
  453. ScriptManager sm = GetCurrent (page);
  454. if (sm.IsInAsyncPostBack)
  455. sm.RegisterArrayDeclaration (arrayName, arrayValue);
  456. else
  457. page.ClientScript.RegisterArrayDeclaration (arrayName, arrayValue);
  458. }
  459. void RegisterArrayDeclaration (string arrayName, string arrayValue) {
  460. if (_arrayDeclarations == null)
  461. _arrayDeclarations = new List<ArrayDeclaration> ();
  462. _arrayDeclarations.Add (new ArrayDeclaration (arrayName, arrayValue));
  463. }
  464. public void RegisterAsyncPostBackControl (Control control) {
  465. if (control == null)
  466. return;
  467. if (_asyncPostBackControls == null)
  468. _asyncPostBackControls = new List<Control> ();
  469. if (_asyncPostBackControls.Contains (control))
  470. return;
  471. _asyncPostBackControls.Add (control);
  472. }
  473. public static void RegisterClientScriptBlock (Control control, Type type, string key, string script, bool addScriptTags) {
  474. RegisterClientScriptBlock (control.Page, type, key, script, addScriptTags);
  475. }
  476. public static void RegisterClientScriptBlock (Page page, Type type, string key, string script, bool addScriptTags) {
  477. ScriptManager sm = GetCurrent (page);
  478. if (sm.IsInAsyncPostBack)
  479. RegisterScript (ref sm._clientScriptBlocks, type, key, script, addScriptTags ? ScriptEntryType.ScriptContentNoTags : ScriptEntryType.ScriptContentWithTags);
  480. else
  481. page.ClientScript.RegisterClientScriptBlock (type, key, script, addScriptTags);
  482. }
  483. public static void RegisterClientScriptInclude (Control control, Type type, string key, string url) {
  484. RegisterClientScriptInclude (control.Page, type, key, url);
  485. }
  486. public static void RegisterClientScriptInclude (Page page, Type type, string key, string url) {
  487. ScriptManager sm = GetCurrent (page);
  488. if (sm.IsInAsyncPostBack)
  489. RegisterScript (ref sm._scriptIncludes, type, key, url, ScriptEntryType.ScriptPath);
  490. else
  491. page.ClientScript.RegisterClientScriptInclude (type, key, url);
  492. }
  493. public static void RegisterClientScriptResource (Control control, Type type, string resourceName) {
  494. RegisterClientScriptResource (control.Page, type, resourceName);
  495. }
  496. public static void RegisterClientScriptResource (Page page, Type type, string resourceName) {
  497. RegisterClientScriptInclude (page, type, "resource-" + resourceName, ScriptResourceHandler.GetResourceUrl (type, resourceName));
  498. }
  499. void RegisterScriptReference (ScriptReference script) {
  500. bool isDebugMode = IsDeploymentRetail ? false : (script.ScriptModeInternal == ScriptMode.Inherit ? IsDebuggingEnabled : (script.ScriptModeInternal == ScriptMode.Debug));
  501. string url;
  502. if (!String.IsNullOrEmpty (script.Path)) {
  503. url = GetScriptName (ResolveClientUrl (script.Path), isDebugMode, EnableScriptLocalization ? script.ResourceUICultures : null);
  504. }
  505. else if (!String.IsNullOrEmpty (script.Name)) {
  506. Assembly assembly;
  507. if (String.IsNullOrEmpty (script.Assembly))
  508. assembly = typeof (ScriptManager).Assembly;
  509. else
  510. assembly = Assembly.Load (script.Assembly);
  511. string name = GetScriptName (script.Name, isDebugMode, null);
  512. if (script.IgnoreScriptPath || String.IsNullOrEmpty (ScriptPath))
  513. url = ScriptResourceHandler.GetResourceUrl (assembly, name, script.NotifyScriptLoaded);
  514. else {
  515. AssemblyName an = assembly.GetName ();
  516. url = ResolveClientUrl (String.Concat (VirtualPathUtility.AppendTrailingSlash (ScriptPath), an.Name, '/', an.Version, '/', name));
  517. }
  518. }
  519. else {
  520. throw new InvalidOperationException ("Name and Path cannot both be empty.");
  521. }
  522. RegisterClientScriptInclude (this, typeof (ScriptManager), url, url);
  523. }
  524. static string GetScriptName (string releaseName, bool isDebugMode, string [] supportedUICultures) {
  525. if (!isDebugMode && (supportedUICultures == null || supportedUICultures.Length == 0))
  526. return releaseName;
  527. if (releaseName.Length < 3 || !releaseName.EndsWith (".js", StringComparison.OrdinalIgnoreCase))
  528. throw new InvalidOperationException (String.Format ("'{0}' is not a valid script path. The path must end in '.js'.", releaseName));
  529. StringBuilder sb = new StringBuilder (releaseName);
  530. sb.Length -= 3;
  531. if (isDebugMode)
  532. sb.Append (".debug");
  533. string culture = Thread.CurrentThread.CurrentUICulture.Name;
  534. if (supportedUICultures != null && Array.IndexOf<string> (supportedUICultures, culture) >= 0)
  535. sb.AppendFormat (".{0}", culture);
  536. sb.Append (".js");
  537. return sb.ToString ();
  538. }
  539. public void RegisterDataItem (Control control, string dataItem) {
  540. RegisterDataItem (control, dataItem, false);
  541. }
  542. public void RegisterDataItem (Control control, string dataItem, bool isJsonSerialized) {
  543. if (!IsInAsyncPostBack)
  544. throw new InvalidOperationException ("RegisterDataItem can only be called during an async postback.");
  545. if (control == null)
  546. throw new ArgumentNullException ("control");
  547. if (_dataItems == null)
  548. _dataItems = new Dictionary<Control, DataItemEntry> ();
  549. if (_dataItems.ContainsKey (control))
  550. throw new ArgumentException (String.Format ("'{0}' already has a data item registered.", control.ID), "control");
  551. _dataItems.Add (control, new DataItemEntry (dataItem, isJsonSerialized));
  552. }
  553. public void RegisterDispose (Control control, string disposeScript) {
  554. throw new NotImplementedException ();
  555. }
  556. public static void RegisterExpandoAttribute (Control control, string controlId, string attributeName, string attributeValue, bool encode) {
  557. Page page = control.Page;
  558. ScriptManager sm = GetCurrent (page);
  559. if (sm.IsInAsyncPostBack)
  560. sm.RegisterExpandoAttribute (controlId, attributeName, attributeValue, encode);
  561. else
  562. page.ClientScript.RegisterExpandoAttribute (controlId, attributeName, attributeValue, encode);
  563. }
  564. private void RegisterExpandoAttribute (string controlId, string attributeName, string attributeValue, bool encode) {
  565. // seems MS do nothing.
  566. }
  567. public static void RegisterHiddenField (Control control, string hiddenFieldName, string hiddenFieldInitialValue) {
  568. RegisterHiddenField (control.Page, hiddenFieldName, hiddenFieldInitialValue);
  569. }
  570. public static void RegisterHiddenField (Page page, string hiddenFieldName, string hiddenFieldInitialValue) {
  571. ScriptManager sm = GetCurrent (page);
  572. if (sm.IsInAsyncPostBack)
  573. sm.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  574. else
  575. page.ClientScript.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  576. }
  577. void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue) {
  578. if (_hiddenFields == null)
  579. _hiddenFields = new Hashtable ();
  580. if (!_hiddenFields.ContainsKey (hiddenFieldName))
  581. _hiddenFields.Add (hiddenFieldName, hiddenFieldInitialValue);
  582. }
  583. public static void RegisterOnSubmitStatement (Control control, Type type, string key, string script) {
  584. RegisterOnSubmitStatement (control.Page, type, key, script);
  585. }
  586. public static void RegisterOnSubmitStatement (Page page, Type type, string key, string script) {
  587. ScriptManager sm = GetCurrent (page);
  588. if (sm.IsInAsyncPostBack)
  589. RegisterScript (ref sm._onSubmitStatements, type, key, script, ScriptEntryType.OnSubmit);
  590. else
  591. page.ClientScript.RegisterOnSubmitStatement (type, key, script);
  592. }
  593. public void RegisterPostBackControl (Control control) {
  594. if (control == null)
  595. return;
  596. if (_postBackControls == null)
  597. _postBackControls = new List<Control> ();
  598. if (_postBackControls.Contains (control))
  599. return;
  600. _postBackControls.Add (control);
  601. }
  602. internal void RegisterUpdatePanel (UpdatePanel updatePanel) {
  603. if (_updatePanels == null)
  604. _updatePanels = new List<UpdatePanel> ();
  605. if (_updatePanels.Contains (updatePanel))
  606. return;
  607. _updatePanels.Add (updatePanel);
  608. }
  609. public void RegisterScriptDescriptors (IExtenderControl extenderControl) {
  610. if (extenderControl == null)
  611. return;
  612. if (_registeredExtenderControls == null || !_registeredExtenderControls.ContainsKey (extenderControl))
  613. return;
  614. Control targetControl = _registeredExtenderControls [extenderControl];
  615. RegisterScriptDescriptors (extenderControl.GetScriptDescriptors (targetControl));
  616. }
  617. public void RegisterScriptDescriptors (IScriptControl scriptControl) {
  618. if (scriptControl == null)
  619. return;
  620. if (_registeredScriptControls == null || !_registeredScriptControls.Contains (scriptControl))
  621. return;
  622. RegisterScriptDescriptors (scriptControl.GetScriptDescriptors ());
  623. }
  624. void RegisterScriptDescriptors (IEnumerable<ScriptDescriptor> scriptDescriptors) {
  625. if (scriptDescriptors == null)
  626. return;
  627. if (IsInAsyncPostBack && !IsInPartialRendering)
  628. return;
  629. StringBuilder sb = new StringBuilder ();
  630. foreach (ScriptDescriptor scriptDescriptor in scriptDescriptors) {
  631. sb.AppendLine ("Sys.Application.add_init(function() {");
  632. sb.AppendLine (scriptDescriptor.GetScript ());
  633. sb.AppendLine ("});");
  634. }
  635. string script = sb.ToString ();
  636. RegisterStartupScript (this, typeof (ExtenderControl), script, script, true);
  637. }
  638. public static void RegisterStartupScript (Control control, Type type, string key, string script, bool addScriptTags) {
  639. RegisterStartupScript (control.Page, type, key, script, addScriptTags);
  640. }
  641. public static void RegisterStartupScript (Page page, Type type, string key, string script, bool addScriptTags) {
  642. ScriptManager sm = GetCurrent (page);
  643. if (sm.IsInAsyncPostBack)
  644. RegisterScript (ref sm._startupScriptBlocks, type, key, script, addScriptTags ? ScriptEntryType.ScriptContentNoTags : ScriptEntryType.ScriptContentWithTags);
  645. else
  646. page.ClientScript.RegisterStartupScript (type, key, script, addScriptTags);
  647. }
  648. public void RegisterScriptControl<TScriptControl> (TScriptControl scriptControl) where TScriptControl : Control, IScriptControl {
  649. if (scriptControl == null)
  650. throw new ArgumentNullException ("scriptControl");
  651. if (_registeredScriptControls == null)
  652. _registeredScriptControls = new List<IScriptControl> ();
  653. if (!_registeredScriptControls.Contains (scriptControl))
  654. _registeredScriptControls.Add (scriptControl);
  655. }
  656. public void RegisterExtenderControl<TExtenderControl> (TExtenderControl extenderControl, Control targetControl) where TExtenderControl : Control, IExtenderControl {
  657. if (extenderControl == null)
  658. throw new ArgumentNullException ("extenderControl");
  659. if (targetControl == null)
  660. throw new ArgumentNullException ("targetControl");
  661. if (_registeredExtenderControls == null)
  662. _registeredExtenderControls = new Dictionary<IExtenderControl, Control> ();
  663. if (!_registeredExtenderControls.ContainsKey (extenderControl))
  664. _registeredExtenderControls.Add (extenderControl, targetControl);
  665. }
  666. static void RegisterScript (ref ScriptEntry scriptList, Type type, string key, string script, ScriptEntryType scriptEntryType) {
  667. ScriptEntry last = null;
  668. ScriptEntry entry = scriptList;
  669. while (entry != null) {
  670. if (entry.Type == type && entry.Key == key)
  671. return;
  672. last = entry;
  673. entry = entry.Next;
  674. }
  675. entry = new ScriptEntry (type, key, script, scriptEntryType);
  676. if (last != null)
  677. last.Next = entry;
  678. else
  679. scriptList = entry;
  680. }
  681. protected override void Render (HtmlTextWriter writer) {
  682. // MSDN: This method is used by control developers to extend the ScriptManager control.
  683. // Notes to Inheritors:
  684. // When overriding this method, call the base Render(HtmlTextWriter) method
  685. // so that PageRequestManager is rendered on the page.
  686. if (SupportsPartialRendering) {
  687. writer.WriteLine ("<script type=\"text/javascript\">");
  688. writer.WriteLine ("//<![CDATA[");
  689. writer.WriteLine ("Sys.WebForms.PageRequestManager._initialize('{0}', document.getElementById('{1}'));", UniqueID, Page.Form.ClientID);
  690. writer.WriteLine ("Sys.WebForms.PageRequestManager.getInstance()._updateControls([{0}], [{1}], [{2}], {3});", FormatUpdatePanelIDs (_updatePanels, true), FormatListIDs (_asyncPostBackControls, true), FormatListIDs (_postBackControls, true), AsyncPostBackTimeout);
  691. writer.WriteLine ("//]]");
  692. writer.WriteLine ("</script>");
  693. }
  694. base.Render (writer);
  695. }
  696. static string FormatUpdatePanelIDs (List<UpdatePanel> list, bool useSingleQuote) {
  697. if (list == null || list.Count == 0)
  698. return null;
  699. StringBuilder sb = new StringBuilder ();
  700. for (int i = 0; i < list.Count; i++) {
  701. sb.AppendFormat ("{0}{1}{2}{0},", useSingleQuote ? "'" : String.Empty, list [i].ChildrenAsTriggers ? "t" : "f", list [i].UniqueID);
  702. }
  703. if (sb.Length > 0)
  704. sb.Length--;
  705. return sb.ToString ();
  706. }
  707. static string FormatListIDs<T> (List<T> list, bool useSingleQuote) where T : Control {
  708. if (list == null || list.Count == 0)
  709. return null;
  710. StringBuilder sb = new StringBuilder ();
  711. for (int i = 0; i < list.Count; i++) {
  712. sb.AppendFormat ("{0}{1}{0},", useSingleQuote ? "'" : String.Empty, list [i].UniqueID);
  713. }
  714. if (sb.Length > 0)
  715. sb.Length--;
  716. return sb.ToString ();
  717. }
  718. public void SetFocus (Control control) {
  719. throw new NotImplementedException ();
  720. }
  721. public void SetFocus (string clientID) {
  722. throw new NotImplementedException ();
  723. }
  724. #region IPostBackDataHandler Members
  725. bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection) {
  726. return LoadPostData (postDataKey, postCollection);
  727. }
  728. void IPostBackDataHandler.RaisePostDataChangedEvent () {
  729. RaisePostDataChangedEvent ();
  730. }
  731. #endregion
  732. static internal void WriteCallbackException (TextWriter output, Exception ex) {
  733. HttpException httpEx = ex as HttpException;
  734. WriteCallbackOutput (output, error, httpEx == null ? "500" : httpEx.GetHttpCode ().ToString (), ex.GetBaseException ().Message);
  735. }
  736. static internal void WriteCallbackRedirect (TextWriter output, string redirectUrl) {
  737. WriteCallbackOutput (output, pageRedirect, null, redirectUrl);
  738. }
  739. internal void WriteCallbackPanel (TextWriter output, UpdatePanel panel, StringBuilder panelOutput) {
  740. if (_panelsToRefresh == null)
  741. _panelsToRefresh = new List<UpdatePanel> ();
  742. _panelsToRefresh.Add (panel);
  743. WriteCallbackOutput (output, updatePanel, panel.ClientID, panelOutput);
  744. }
  745. internal void RegisterChildUpdatePanel (UpdatePanel updatePanel) {
  746. if (_childUpdatePanels == null)
  747. _childUpdatePanels = new List<UpdatePanel> ();
  748. _childUpdatePanels.Add (updatePanel);
  749. }
  750. static void WriteCallbackOutput (TextWriter output, string type, string name, object value) {
  751. string str = value as string;
  752. StringBuilder sb = value as StringBuilder;
  753. int length = 0;
  754. if (str != null)
  755. length = str.Length;
  756. else if (sb != null)
  757. length = sb.Length;
  758. //output.Write ("{0}|{1}|{2}|{3}|", value == null ? 0 : value.Length, type, name, value);
  759. output.Write (length);
  760. output.Write ('|');
  761. output.Write (type);
  762. output.Write ('|');
  763. output.Write (name);
  764. output.Write ('|');
  765. for (int i = 0; i < length; i++)
  766. if (str != null)
  767. output.Write (str [i]);
  768. else
  769. output.Write (sb [i]);
  770. output.Write ('|');
  771. }
  772. void RenderPageCallback (HtmlTextWriter output, Control container) {
  773. Page page = (Page) container;
  774. page.Form.SetRenderMethodDelegate (RenderFormCallback);
  775. HtmlTextParser parser = new HtmlTextParser (output);
  776. page.Form.RenderControl (parser);
  777. WriteCallbackOutput (output, asyncPostBackControlIDs, null, FormatListIDs (_asyncPostBackControls, false));
  778. WriteCallbackOutput (output, postBackControlIDs, null, FormatListIDs (_postBackControls, false));
  779. WriteCallbackOutput (output, updatePanelIDs, null, FormatUpdatePanelIDs (_updatePanels, false));
  780. WriteCallbackOutput (output, childUpdatePanelIDs, null, FormatListIDs (_childUpdatePanels, false));
  781. WriteCallbackOutput (output, panelsToRefreshIDs, null, FormatListIDs (_panelsToRefresh, false));
  782. WriteCallbackOutput (output, asyncPostBackTimeout, null, AsyncPostBackTimeout.ToString ());
  783. WriteCallbackOutput (output, pageTitle, null, Page.Title);
  784. if (_dataItems != null)
  785. foreach (Control control in _dataItems.Keys) {
  786. DataItemEntry entry = _dataItems [control];
  787. WriteCallbackOutput (output, entry.IsJsonSerialized ? dataItemJson : dataItem, control.ClientID, entry.DataItem);
  788. }
  789. WriteArrayDeclarations (output);
  790. WriteScriptBlocks (output, _clientScriptBlocks);
  791. WriteScriptBlocks (output, _scriptIncludes);
  792. WriteScriptBlocks (output, _startupScriptBlocks);
  793. WriteScriptBlocks (output, _onSubmitStatements);
  794. WriteHiddenFields (output);
  795. }
  796. void WriteArrayDeclarations (HtmlTextWriter writer) {
  797. if (_arrayDeclarations != null) {
  798. for (int i = 0; i < _arrayDeclarations.Count; i++) {
  799. ArrayDeclaration array = _arrayDeclarations [i];
  800. WriteCallbackOutput (writer, arrayDeclaration, array.ArrayName, array.ArrayValue);
  801. }
  802. }
  803. }
  804. void WriteScriptBlocks (HtmlTextWriter output, ScriptEntry scriptList) {
  805. while (scriptList != null) {
  806. switch (scriptList.ScriptEntryType) {
  807. case ScriptEntryType.ScriptContentNoTags:
  808. WriteCallbackOutput (output, scriptBlock, scriptContentNoTags, scriptList.Script);
  809. break;
  810. case ScriptEntryType.ScriptContentWithTags:
  811. string script = SerializeScriptBlock (scriptList);
  812. WriteCallbackOutput (output, scriptBlock, scriptContentWithTags, script);
  813. break;
  814. case ScriptEntryType.ScriptPath:
  815. WriteCallbackOutput (output, scriptBlock, scriptPath, scriptList.Script);
  816. break;
  817. case ScriptEntryType.OnSubmit:
  818. WriteCallbackOutput (output, onSubmit, null, scriptList.Script);
  819. break;
  820. }
  821. scriptList = scriptList.Next;
  822. }
  823. }
  824. void WriteHiddenFields (HtmlTextWriter output) {
  825. if (_hiddenFields == null)
  826. return;
  827. foreach (string key in _hiddenFields.Keys) {
  828. string value = _hiddenFields [key] as string;
  829. WriteCallbackOutput (output, hiddenField, key, value);
  830. }
  831. }
  832. [MonoTODO ()]
  833. static string SerializeScriptBlock (ScriptEntry scriptList) {
  834. 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));
  835. }
  836. void RenderFormCallback (HtmlTextWriter output, Control container) {
  837. output = ((HtmlTextParser) output).ResponseOutput;
  838. HtmlForm form = (HtmlForm) container;
  839. HtmlTextWriter writer = new HtmlDropWriter (output);
  840. if (form.HasControls ()) {
  841. for (int i = 0; i < form.Controls.Count; i++) {
  842. form.Controls [i].RenderControl (writer);
  843. }
  844. }
  845. }
  846. internal class AlternativeHtmlTextWriter : HtmlTextWriter
  847. {
  848. readonly HtmlTextWriter _responseOutput;
  849. public HtmlTextWriter ResponseOutput {
  850. get { return _responseOutput; }
  851. }
  852. public AlternativeHtmlTextWriter (TextWriter writer, HtmlTextWriter responseOutput)
  853. : base (writer) {
  854. _responseOutput = responseOutput;
  855. }
  856. }
  857. sealed class HtmlTextParser : AlternativeHtmlTextWriter
  858. {
  859. public HtmlTextParser (HtmlTextWriter responseOutput)
  860. : base (new TextParser (responseOutput), responseOutput) {
  861. }
  862. }
  863. sealed class TextParser : TextWriter
  864. {
  865. int _state;
  866. char _charState = (char) 255;
  867. const char nullCharState = (char) 255;
  868. StringBuilder _sb = new StringBuilder ();
  869. Dictionary<string, string> _currentField;
  870. string _currentAttribute;
  871. readonly HtmlTextWriter _responseOutput;
  872. public override Encoding Encoding {
  873. get { return Encoding.UTF8; }
  874. }
  875. public TextParser (HtmlTextWriter responseOutput) {
  876. _responseOutput = responseOutput;
  877. }
  878. public override void Write (char value) {
  879. switch (_state) {
  880. case 0:
  881. ParseBeginTag (value);
  882. break;
  883. case 1:
  884. ParseAttributeName (value);
  885. break;
  886. case 2:
  887. ParseAttributeValue (value);
  888. break;
  889. }
  890. }
  891. private void ParseAttributeValue (char value) {
  892. switch (value) {
  893. case '>':
  894. ResetState ();
  895. break;
  896. case '"':
  897. _currentField.Add (_currentAttribute, _sb.ToString ());
  898. _state = 1;
  899. _sb.Length = 0;
  900. ProbeWriteOutput ();
  901. break;
  902. default:
  903. _sb.Append (value);
  904. break;
  905. }
  906. }
  907. private void ParseAttributeName (char value) {
  908. switch (value) {
  909. case '>':
  910. ResetState ();
  911. break;
  912. case ' ':
  913. case '=':
  914. break;
  915. case '"':
  916. _currentAttribute = _sb.ToString ();
  917. _state = 2;
  918. _sb.Length = 0;
  919. break;
  920. default:
  921. _sb.Append (value);
  922. break;
  923. }
  924. }
  925. void ParseBeginTag (char value) {
  926. switch (_charState) {
  927. case nullCharState:
  928. if (value == '<')
  929. _charState = value;
  930. break;
  931. case '<':
  932. if (value == 'i')
  933. _charState = value;
  934. else
  935. ResetState ();
  936. break;
  937. case 'i':
  938. if (value == 'n')
  939. _charState = value;
  940. else
  941. ResetState ();
  942. break;
  943. case 'n':
  944. if (value == 'p')
  945. _charState = value;
  946. else
  947. ResetState ();
  948. break;
  949. case 'p':
  950. if (value == 'u')
  951. _charState = value;
  952. else
  953. ResetState ();
  954. break;
  955. case 'u':
  956. if (value == 't')
  957. _charState = value;
  958. else
  959. ResetState ();
  960. break;
  961. case 't':
  962. if (value == ' ') {
  963. _state = 1;
  964. _currentField = new Dictionary<string, string> ();
  965. }
  966. else
  967. ResetState ();
  968. break;
  969. }
  970. }
  971. private void ResetState () {
  972. _charState = nullCharState;
  973. _state = 0;
  974. _sb.Length = 0;
  975. }
  976. private void ProbeWriteOutput () {
  977. if (!_currentField.ContainsKey ("name"))
  978. return;
  979. if (!_currentField.ContainsKey ("value"))
  980. return;
  981. string value = _currentField ["value"];
  982. if (String.IsNullOrEmpty (value))
  983. return;
  984. ScriptManager.WriteCallbackOutput (_responseOutput, ScriptManager.hiddenField, _currentField ["name"], value);
  985. }
  986. }
  987. sealed class HtmlDropWriter : AlternativeHtmlTextWriter
  988. {
  989. public HtmlDropWriter (HtmlTextWriter responseOutput)
  990. : base (new DropWriter (), responseOutput) {
  991. }
  992. }
  993. sealed class DropWriter : TextWriter
  994. {
  995. public override Encoding Encoding {
  996. get { return Encoding.UTF8; }
  997. }
  998. }
  999. sealed class ScriptEntry
  1000. {
  1001. readonly public Type Type;
  1002. readonly public string Key;
  1003. readonly public string Script;
  1004. readonly public ScriptEntryType ScriptEntryType;
  1005. public ScriptEntry Next;
  1006. public ScriptEntry (Type type, string key, string script, ScriptEntryType scriptEntryType) {
  1007. Key = key;
  1008. Type = type;
  1009. Script = script;
  1010. ScriptEntryType = scriptEntryType;
  1011. }
  1012. }
  1013. enum ScriptEntryType
  1014. {
  1015. ScriptContentNoTags,
  1016. ScriptContentWithTags,
  1017. ScriptPath,
  1018. OnSubmit
  1019. }
  1020. sealed class ArrayDeclaration
  1021. {
  1022. readonly public string ArrayName;
  1023. readonly public string ArrayValue;
  1024. public ArrayDeclaration (string arrayName, string arrayValue) {
  1025. ArrayName = arrayName;
  1026. ArrayValue = arrayValue;
  1027. }
  1028. }
  1029. sealed class CultureInfoConverter : JavaScriptConverter
  1030. {
  1031. private CultureInfoConverter () { }
  1032. static readonly Type typeofCultureInfo = typeof (CultureInfo);
  1033. static CultureInfoConverter _instance = new CultureInfoConverter ();
  1034. public static IEnumerable<JavaScriptConverter> GetConverters () { yield return _instance; }
  1035. public override IEnumerable<Type> SupportedTypes {
  1036. get { yield return typeofCultureInfo; }
  1037. }
  1038. public override object Deserialize (IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer) {
  1039. throw new NotSupportedException ();
  1040. }
  1041. public override IDictionary<string, object> Serialize (object obj, JavaScriptSerializer serializer) {
  1042. CultureInfo ci = (CultureInfo) obj;
  1043. if (ci == null)
  1044. return null;
  1045. Dictionary<string, object> d = new Dictionary<string, object> (StringComparer.Ordinal);
  1046. d.Add ("name", ci.Name);
  1047. d.Add ("numberFormat", ci.NumberFormat);
  1048. d.Add ("dateTimeFormat", ci.DateTimeFormat);
  1049. return d;
  1050. }
  1051. }
  1052. sealed class ScriptReferenceEntry
  1053. {
  1054. readonly Control _control;
  1055. readonly ScriptReference _scriptReference;
  1056. public Control Control { get { return _control; } }
  1057. public ScriptReference ScriptReference { get { return _scriptReference; } }
  1058. public ScriptReferenceEntry (Control control, ScriptReference scriptReference) {
  1059. _control = control;
  1060. _scriptReference = scriptReference;
  1061. }
  1062. }
  1063. sealed class DataItemEntry
  1064. {
  1065. readonly string _dataItem;
  1066. readonly bool _isJsonSerialized;
  1067. public string DataItem { get { return _dataItem; } }
  1068. public bool IsJsonSerialized { get { return _isJsonSerialized; } }
  1069. public DataItemEntry (string dataItem, bool isJsonSerialized) {
  1070. _dataItem = dataItem;
  1071. _isJsonSerialized = isJsonSerialized;
  1072. }
  1073. }
  1074. }
  1075. }