ScriptManager.cs 39 KB

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