2
0

ScriptManager.cs 39 KB

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