ScriptManager.cs 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  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. using System.Xml;
  46. using System.Collections.ObjectModel;
  47. namespace System.Web.UI
  48. {
  49. [ParseChildrenAttribute (true)]
  50. [DefaultPropertyAttribute ("Scripts")]
  51. [DesignerAttribute ("System.Web.UI.Design.ScriptManagerDesigner, System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
  52. [NonVisualControlAttribute]
  53. [PersistChildrenAttribute (false)]
  54. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  55. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  56. public class ScriptManager : Control, IPostBackDataHandler, IScriptManager
  57. {
  58. // the keywords are used in fomatting async response
  59. const string updatePanel = "updatePanel";
  60. const string hiddenField = "hiddenField";
  61. const string arrayDeclaration = "arrayDeclaration";
  62. const string scriptBlock = "scriptBlock";
  63. #if NET_3_5
  64. const string scriptStartupBlock = "scriptStartupBlock";
  65. #endif
  66. const string expando = "expando";
  67. const string onSubmit = "onSubmit";
  68. const string asyncPostBackControlIDs = "asyncPostBackControlIDs";
  69. const string postBackControlIDs = "postBackControlIDs";
  70. const string updatePanelIDs = "updatePanelIDs";
  71. const string asyncPostBackTimeout = "asyncPostBackTimeout";
  72. const string childUpdatePanelIDs = "childUpdatePanelIDs";
  73. const string panelsToRefreshIDs = "panelsToRefreshIDs";
  74. const string formAction = "formAction";
  75. const string dataItem = "dataItem";
  76. const string dataItemJson = "dataItemJson";
  77. const string scriptDispose = "scriptDispose";
  78. const string pageRedirect = "pageRedirect";
  79. const string error = "error";
  80. const string pageTitle = "pageTitle";
  81. const string focus = "focus";
  82. const string scriptContentNoTags = "ScriptContentNoTags";
  83. const string scriptContentWithTags = "ScriptContentWithTags";
  84. const string scriptPath = "ScriptPath";
  85. static readonly object ScriptManagerKey = typeof (IScriptManager);
  86. int _asyncPostBackTimeout = 90;
  87. List<Control> _asyncPostBackControls;
  88. List<Control> _postBackControls;
  89. List<UpdatePanel> _childUpdatePanels;
  90. List<UpdatePanel> _panelsToRefresh;
  91. List<UpdatePanel> _updatePanels;
  92. ScriptReferenceCollection _scripts;
  93. ServiceReferenceCollection _services;
  94. bool _isInAsyncPostBack;
  95. bool _isInPartialRendering;
  96. string _asyncPostBackSourceElementID;
  97. ScriptMode _scriptMode = ScriptMode.Auto;
  98. bool _enableScriptGlobalization;
  99. bool _enableScriptLocalization;
  100. string _scriptPath;
  101. List<RegisteredScript> _clientScriptBlocks;
  102. List<RegisteredScript> _startupScriptBlocks;
  103. List<RegisteredScript> _onSubmitStatements;
  104. List<RegisteredArrayDeclaration> _arrayDeclarations;
  105. List<RegisteredExpandoAttribute> _expandoAttributes;
  106. List<RegisteredHiddenField> _hiddenFields;
  107. List<IScriptControl> _registeredScriptControls;
  108. Dictionary<IExtenderControl, Control> _registeredExtenderControls;
  109. bool? _supportsPartialRendering;
  110. bool _enablePartialRendering = true;
  111. bool _init;
  112. string _panelToRefreshID;
  113. Dictionary<Control, DataItemEntry> _dataItems;
  114. bool _enablePageMethods;
  115. string _controlIDToFocus;
  116. bool _allowCustomErrorsRedirect = true;
  117. string _asyncPostBackErrorMessage;
  118. List<RegisteredDisposeScript> _disposeScripts;
  119. List<ScriptReferenceEntry> _scriptToRegister;
  120. bool _loadScriptsBeforeUI = true;
  121. AuthenticationServiceManager _authenticationService;
  122. ProfileServiceManager _profileService;
  123. List<ScriptManagerProxy> _proxies;
  124. [DefaultValue (true)]
  125. [Category ("Behavior")]
  126. public bool AllowCustomErrorsRedirect {
  127. get {
  128. return _allowCustomErrorsRedirect;
  129. }
  130. set {
  131. _allowCustomErrorsRedirect = value;
  132. }
  133. }
  134. [Category ("Behavior")]
  135. [DefaultValue ("")]
  136. public string AsyncPostBackErrorMessage {
  137. get {
  138. if (String.IsNullOrEmpty (_asyncPostBackErrorMessage))
  139. return String.Empty;
  140. return _asyncPostBackErrorMessage;
  141. }
  142. set {
  143. _asyncPostBackErrorMessage = value;
  144. }
  145. }
  146. [Browsable (false)]
  147. public string AsyncPostBackSourceElementID {
  148. get {
  149. if (_asyncPostBackSourceElementID == null)
  150. return String.Empty;
  151. return _asyncPostBackSourceElementID;
  152. }
  153. }
  154. [DefaultValue (90)]
  155. [Category ("Behavior")]
  156. public int AsyncPostBackTimeout {
  157. get {
  158. return _asyncPostBackTimeout;
  159. }
  160. set {
  161. _asyncPostBackTimeout = value;
  162. }
  163. }
  164. [Category ("Behavior")]
  165. [MergableProperty (false)]
  166. [DefaultValue ("")]
  167. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  168. [PersistenceMode (PersistenceMode.InnerProperty)]
  169. public AuthenticationServiceManager AuthenticationService {
  170. get {
  171. if (_authenticationService == null)
  172. _authenticationService = new AuthenticationServiceManager ();
  173. return _authenticationService;
  174. }
  175. }
  176. [Category ("Behavior")]
  177. [DefaultValue (false)]
  178. public bool EnablePageMethods {
  179. get {
  180. return _enablePageMethods;
  181. }
  182. set {
  183. _enablePageMethods = value;
  184. }
  185. }
  186. [DefaultValue (true)]
  187. [Category ("Behavior")]
  188. public bool EnablePartialRendering {
  189. get {
  190. return _enablePartialRendering;
  191. }
  192. set {
  193. if (_init)
  194. throw new InvalidOperationException ();
  195. _enablePartialRendering = value;
  196. }
  197. }
  198. [DefaultValue (false)]
  199. [Category ("Behavior")]
  200. public bool EnableScriptGlobalization {
  201. get {
  202. return _enableScriptGlobalization;
  203. }
  204. set {
  205. _enableScriptGlobalization = value;
  206. }
  207. }
  208. [Category ("Behavior")]
  209. [DefaultValue (false)]
  210. public bool EnableScriptLocalization {
  211. get {
  212. return _enableScriptLocalization;
  213. }
  214. set {
  215. _enableScriptLocalization = value;
  216. }
  217. }
  218. [Browsable (false)]
  219. public bool IsDebuggingEnabled {
  220. get {
  221. if (IsDeploymentRetail)
  222. return false;
  223. CompilationSection compilation = (CompilationSection) WebConfigurationManager.GetSection ("system.web/compilation");
  224. if (!compilation.Debug && (ScriptMode == ScriptMode.Auto || ScriptMode == ScriptMode.Inherit))
  225. return false;
  226. if (ScriptMode == ScriptMode.Release)
  227. return false;
  228. return true;
  229. }
  230. }
  231. internal bool IsDeploymentRetail {
  232. get {
  233. #if TARGET_J2EE
  234. return false;
  235. #else
  236. DeploymentSection deployment = (DeploymentSection) WebConfigurationManager.GetSection ("system.web/deployment");
  237. return deployment.Retail;
  238. #endif
  239. }
  240. }
  241. [Browsable (false)]
  242. public bool IsInAsyncPostBack {
  243. get {
  244. return _isInAsyncPostBack;
  245. }
  246. }
  247. internal bool IsInPartialRendering {
  248. get {
  249. return _isInPartialRendering;
  250. }
  251. set {
  252. _isInPartialRendering = value;
  253. }
  254. }
  255. [Category ("Behavior")]
  256. [DefaultValue (true)]
  257. public bool LoadScriptsBeforeUI {
  258. get {
  259. return _loadScriptsBeforeUI;
  260. }
  261. set {
  262. _loadScriptsBeforeUI = value;
  263. }
  264. }
  265. [PersistenceMode (PersistenceMode.InnerProperty)]
  266. [DefaultValue ("")]
  267. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  268. [Category ("Behavior")]
  269. [MergableProperty (false)]
  270. public ProfileServiceManager ProfileService {
  271. get {
  272. if (_profileService == null)
  273. _profileService = new ProfileServiceManager ();
  274. return _profileService;
  275. }
  276. }
  277. [Category ("Behavior")]
  278. #if TARGET_J2EE
  279. [MonoLimitation ("The 'Auto' value is the same as 'Debug'.")]
  280. #endif
  281. public ScriptMode ScriptMode {
  282. get {
  283. return _scriptMode;
  284. }
  285. set {
  286. if (value == ScriptMode.Inherit)
  287. value = ScriptMode.Auto;
  288. _scriptMode = value;
  289. }
  290. }
  291. [DefaultValue ("")]
  292. [Category ("Behavior")]
  293. public string ScriptPath {
  294. get {
  295. if (_scriptPath == null)
  296. return String.Empty;
  297. return _scriptPath;
  298. }
  299. set {
  300. _scriptPath = value;
  301. }
  302. }
  303. [PersistenceMode (PersistenceMode.InnerProperty)]
  304. [DefaultValue ("")]
  305. [Category ("Behavior")]
  306. [MergableProperty (false)]
  307. public ScriptReferenceCollection Scripts {
  308. get {
  309. if (_scripts == null)
  310. _scripts = new ScriptReferenceCollection ();
  311. return _scripts;
  312. }
  313. }
  314. [PersistenceMode (PersistenceMode.InnerProperty)]
  315. [DefaultValue ("")]
  316. [MergableProperty (false)]
  317. [Category ("Behavior")]
  318. public ServiceReferenceCollection Services {
  319. get {
  320. if (_services == null)
  321. _services = new ServiceReferenceCollection ();
  322. return _services;
  323. }
  324. }
  325. [DefaultValue (true)]
  326. [Browsable (false)]
  327. public bool SupportsPartialRendering {
  328. get {
  329. if (!_supportsPartialRendering.HasValue)
  330. _supportsPartialRendering = CheckSupportsPartialRendering ();
  331. return _supportsPartialRendering.Value;
  332. }
  333. set {
  334. if (_init)
  335. throw new InvalidOperationException ();
  336. if (!EnablePartialRendering && value)
  337. throw new InvalidOperationException ("The SupportsPartialRendering property cannot be set when EnablePartialRendering is false.");
  338. _supportsPartialRendering = value;
  339. }
  340. }
  341. bool CheckSupportsPartialRendering () {
  342. if (!EnablePartialRendering)
  343. return false;
  344. // TODO: consider browser capabilities
  345. return true;
  346. }
  347. [EditorBrowsable (EditorBrowsableState.Never)]
  348. [Browsable (false)]
  349. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  350. public override bool Visible {
  351. get {
  352. return true;
  353. }
  354. set {
  355. throw new NotImplementedException ();
  356. }
  357. }
  358. [Category ("Action")]
  359. public event EventHandler<AsyncPostBackErrorEventArgs> AsyncPostBackError;
  360. [Category ("Action")]
  361. public event EventHandler<ScriptReferenceEventArgs> ResolveScriptReference;
  362. public static ScriptManager GetCurrent (Page page) {
  363. if (page == null)
  364. throw new ArgumentNullException ("page");
  365. return GetCurrentInternal (page);
  366. }
  367. static ScriptManager GetCurrentInternal (Page page)
  368. {
  369. if (page == null)
  370. return null;
  371. return (ScriptManager) page.Items [ScriptManagerKey];
  372. }
  373. static void SetCurrent (Page page, ScriptManager instance) {
  374. page.Items [ScriptManagerKey] = instance;
  375. page.ClientScript.RegisterWebFormClientScript ();
  376. }
  377. UpdatePanel FindPanelWithId (string id)
  378. {
  379. if (_updatePanels == null)
  380. return null;
  381. foreach (UpdatePanel panel in _updatePanels) {
  382. if (panel.ID == id)
  383. return panel;
  384. }
  385. return null;
  386. }
  387. protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection) {
  388. _isInAsyncPostBack = true;
  389. string arg = postCollection [postDataKey];
  390. if (!String.IsNullOrEmpty (arg)) {
  391. string [] args = arg.Split ('|');
  392. switch (args.Length) {
  393. case 1:
  394. _asyncPostBackSourceElementID = args [0];
  395. break;
  396. case 2:
  397. _panelToRefreshID = args [0];
  398. _asyncPostBackSourceElementID = args [1];
  399. break;
  400. default: // "impossible situation"
  401. throw new InvalidOperationException ("Unexpected format of post data.");
  402. }
  403. return true;
  404. }
  405. return false;
  406. }
  407. protected internal virtual void OnAsyncPostBackError (AsyncPostBackErrorEventArgs e) {
  408. if (AsyncPostBackError != null)
  409. AsyncPostBackError (this, e);
  410. }
  411. protected override void OnInit (EventArgs e) {
  412. base.OnInit (e);
  413. if (GetCurrentInternal (Page) != null)
  414. throw new InvalidOperationException ("Only one instance of a ScriptManager can be added to the page.");
  415. SetCurrent (Page, this);
  416. Page.Error += new EventHandler (OnPageError);
  417. _init = true;
  418. }
  419. void OnPageError (object sender, EventArgs e) {
  420. if (IsInAsyncPostBack)
  421. OnAsyncPostBackError (new AsyncPostBackErrorEventArgs (Context.Error));
  422. }
  423. protected override void OnPreRender (EventArgs e) {
  424. base.OnPreRender (e);
  425. Page.PreRenderComplete += new EventHandler (OnPreRenderComplete);
  426. if (IsInAsyncPostBack) {
  427. Page.SetRenderMethodDelegate (RenderPageCallback);
  428. }
  429. else {
  430. if (EnableScriptGlobalization) {
  431. CultureInfo culture = Thread.CurrentThread.CurrentCulture;
  432. string script = String.Format ("var __cultureInfo = '{0}';", JavaScriptSerializer.DefaultSerializer.Serialize (new CultureInfoSerializer (culture)));
  433. RegisterClientScriptBlock (this, typeof (ScriptManager), "ScriptGlobalization", script, true);
  434. }
  435. // Register dispose script
  436. if (_disposeScripts != null && _disposeScripts.Count > 0) {
  437. StringBuilder sb = new StringBuilder ();
  438. sb.AppendLine ();
  439. for (int i = 0; i < _disposeScripts.Count; i++) {
  440. RegisteredDisposeScript entry = _disposeScripts [i];
  441. if (IsMultiForm)
  442. sb.Append ("Sys.WebForms.PageRequestManager.getInstance($get(\"" + Page.Form.ClientID + "\"))._registerDisposeScript(\"");
  443. else
  444. sb.Append ("Sys.WebForms.PageRequestManager.getInstance()._registerDisposeScript(\"");
  445. sb.Append (entry.UpdatePanel.ClientID);
  446. sb.Append ("\", ");
  447. sb.Append (JavaScriptSerializer.DefaultSerializer.Serialize (entry.Script)); //JavaScriptSerializer.Serialize used escape script literal
  448. sb.AppendLine (");");
  449. }
  450. RegisterStartupScript (this, typeof (ExtenderControl), "disposeScripts;", sb.ToString (), true);
  451. }
  452. #if TARGET_DOTNET
  453. // to cause webform client script being included
  454. Page.ClientScript.GetPostBackEventReference (new PostBackOptions (this, null, null, false, false, false, true, true, null));
  455. #else
  456. Page.ClientScript.GetPostBackEventReference (this, null);
  457. #endif
  458. }
  459. }
  460. void OnPreRenderComplete (object sender, EventArgs e) {
  461. // Resolve Scripts
  462. ScriptReference ajaxScript = new ScriptReference ("MicrosoftAjax.js", String.Empty);
  463. ajaxScript.NotifyScriptLoaded = false;
  464. OnResolveScriptReference (new ScriptReferenceEventArgs (ajaxScript));
  465. ScriptReference ajaxWebFormsScript = new ScriptReference ("MicrosoftAjaxWebForms.js", String.Empty);
  466. ajaxWebFormsScript.NotifyScriptLoaded = false;
  467. OnResolveScriptReference (new ScriptReferenceEventArgs (ajaxWebFormsScript));
  468. ScriptReference ajaxExtensionScript = null;
  469. ScriptReference ajaxWebFormsExtensionScript = null;
  470. if (IsMultiForm) {
  471. ajaxExtensionScript = new ScriptReference ("MicrosoftAjaxExtension.js", String.Empty);
  472. OnResolveScriptReference (new ScriptReferenceEventArgs (ajaxExtensionScript));
  473. ajaxWebFormsExtensionScript = new ScriptReference ("MicrosoftAjaxWebFormsExtension.js", String.Empty);
  474. OnResolveScriptReference (new ScriptReferenceEventArgs (ajaxWebFormsExtensionScript));
  475. }
  476. foreach (ScriptReferenceEntry script in GetScriptReferences ()) {
  477. OnResolveScriptReference (new ScriptReferenceEventArgs (script.ScriptReference));
  478. if (_scriptToRegister == null)
  479. _scriptToRegister = new List<ScriptReferenceEntry> ();
  480. _scriptToRegister.Add (script);
  481. }
  482. if (!IsInAsyncPostBack) {
  483. // Register Ajax framework script.
  484. RegisterScriptReference (this, ajaxScript, true);
  485. if (IsMultiForm) {
  486. RegisterScriptReference (this, ajaxExtensionScript, true);
  487. RegisterClientScriptBlock (this, typeof (ScriptManager), "Sys.Application", "\nSys.Application._initialize(document.getElementById('" + Page.Form.ClientID + "'));\n", true);
  488. }
  489. StringBuilder sb = new StringBuilder ();
  490. sb.AppendLine ("if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');");
  491. ScriptingProfileServiceSection profileService = (ScriptingProfileServiceSection) WebConfigurationManager.GetSection ("system.web.extensions/scripting/webServices/profileService");
  492. if (profileService != null && profileService.Enabled)
  493. sb.AppendLine ("Sys.Services._ProfileService.DefaultWebServicePath = '" + ResolveClientUrl ("~" + System.Web.Script.Services.ProfileService.DefaultWebServicePath) + "';");
  494. string profileServicePath = GetProfileServicePath ();
  495. if (!String.IsNullOrEmpty (profileServicePath))
  496. sb.AppendLine ("Sys.Services.ProfileService.set_path('" + profileServicePath + "');");
  497. ScriptingAuthenticationServiceSection authenticationService = (ScriptingAuthenticationServiceSection) WebConfigurationManager.GetSection ("system.web.extensions/scripting/webServices/authenticationService");
  498. if (authenticationService != null && authenticationService.Enabled) {
  499. sb.AppendLine ("Sys.Services._AuthenticationService.DefaultWebServicePath = '" + ResolveClientUrl ("~/Authentication_JSON_AppService.axd") + "';");
  500. if (Page.User.Identity.IsAuthenticated)
  501. sb.AppendLine ("Sys.Services.AuthenticationService._setAuthenticated(true);");
  502. }
  503. string authenticationServicePath = GetAuthenticationServicePath ();
  504. if (!String.IsNullOrEmpty (authenticationServicePath))
  505. sb.AppendLine ("Sys.Services.AuthenticationService.set_path('" + authenticationServicePath + "');");
  506. RegisterClientScriptBlock (this, typeof (ScriptManager), "Framework", sb.ToString (), true);
  507. RegisterScriptReference (this, ajaxWebFormsScript, true);
  508. if (IsMultiForm)
  509. RegisterScriptReference (this, ajaxWebFormsExtensionScript, true);
  510. }
  511. // Register Scripts
  512. if (_scriptToRegister != null)
  513. for (int i = 0; i < _scriptToRegister.Count; i++)
  514. RegisterScriptReference (_scriptToRegister [i].Control, _scriptToRegister [i].ScriptReference, _scriptToRegister [i].LoadScriptsBeforeUI);
  515. if (!IsInAsyncPostBack) {
  516. // Register services
  517. if (_services != null && _services.Count > 0) {
  518. for (int i = 0; i < _services.Count; i++) {
  519. RegisterServiceReference (this, _services [i]);
  520. }
  521. }
  522. if (_proxies != null && _proxies.Count > 0) {
  523. for (int i = 0; i < _proxies.Count; i++) {
  524. ScriptManagerProxy proxy = _proxies [i];
  525. for (int j = 0; j < proxy.Services.Count; j++) {
  526. RegisterServiceReference (proxy, proxy.Services [j]);
  527. }
  528. }
  529. }
  530. if (EnablePageMethods) {
  531. LogicalTypeInfo logicalTypeInfo = LogicalTypeInfo.GetLogicalTypeInfo (Page.GetType (), Page.Request.FilePath);
  532. RegisterClientScriptBlock (this, typeof (ScriptManager), "PageMethods", logicalTypeInfo.Proxy, true);
  533. }
  534. // Register startup script
  535. if (IsMultiForm)
  536. RegisterStartupScript (this, typeof (ExtenderControl), "Sys.Application.initialize();", "Sys.Application.getInstance($get(\"" + Page.Form.ClientID + "\")).initialize();\n", true);
  537. else
  538. RegisterStartupScript (this, typeof (ExtenderControl), "Sys.Application.initialize();", "Sys.Application.initialize();\n", true);
  539. }
  540. }
  541. string GetProfileServicePath () {
  542. if (_profileService != null && !String.IsNullOrEmpty (_profileService.Path))
  543. return ResolveClientUrl (_profileService.Path);
  544. if (_proxies != null && _proxies.Count > 0)
  545. for (int i = 0; i < _proxies.Count; i++)
  546. if (!String.IsNullOrEmpty (_proxies [i].ProfileService.Path))
  547. return _proxies [i].ResolveClientUrl (_proxies [i].ProfileService.Path);
  548. return null;
  549. }
  550. string GetAuthenticationServicePath () {
  551. if (_authenticationService != null && !String.IsNullOrEmpty (_authenticationService.Path))
  552. return ResolveClientUrl (_authenticationService.Path);
  553. if (_proxies != null && _proxies.Count > 0)
  554. for (int i = 0; i < _proxies.Count; i++)
  555. if (!String.IsNullOrEmpty (_proxies [i].AuthenticationService.Path))
  556. return _proxies [i].ResolveClientUrl (_proxies [i].AuthenticationService.Path);
  557. return null;
  558. }
  559. public ReadOnlyCollection<RegisteredArrayDeclaration> GetRegisteredArrayDeclarations () {
  560. if (_arrayDeclarations == null)
  561. _arrayDeclarations = new List<RegisteredArrayDeclaration> ();
  562. return new ReadOnlyCollection<RegisteredArrayDeclaration> (_arrayDeclarations);
  563. }
  564. public ReadOnlyCollection<RegisteredScript> GetRegisteredClientScriptBlocks () {
  565. if (_clientScriptBlocks == null)
  566. _clientScriptBlocks = new List<RegisteredScript> ();
  567. return new ReadOnlyCollection<RegisteredScript> (_clientScriptBlocks);
  568. }
  569. public ReadOnlyCollection<RegisteredDisposeScript> GetRegisteredDisposeScripts () {
  570. if (_disposeScripts == null)
  571. _disposeScripts = new List<RegisteredDisposeScript> ();
  572. return new ReadOnlyCollection<RegisteredDisposeScript> (_disposeScripts);
  573. }
  574. public ReadOnlyCollection<RegisteredExpandoAttribute> GetRegisteredExpandoAttributes () {
  575. if (_expandoAttributes == null)
  576. _expandoAttributes = new List<RegisteredExpandoAttribute> ();
  577. return new ReadOnlyCollection<RegisteredExpandoAttribute> (_expandoAttributes);
  578. }
  579. public ReadOnlyCollection<RegisteredHiddenField> GetRegisteredHiddenFields () {
  580. if (_hiddenFields == null)
  581. _hiddenFields = new List<RegisteredHiddenField> ();
  582. return new ReadOnlyCollection<RegisteredHiddenField> (_hiddenFields);
  583. }
  584. public ReadOnlyCollection<RegisteredScript> GetRegisteredOnSubmitStatements () {
  585. if (_onSubmitStatements == null)
  586. _onSubmitStatements = new List<RegisteredScript> ();
  587. return new ReadOnlyCollection<RegisteredScript> (_onSubmitStatements);
  588. }
  589. public ReadOnlyCollection<RegisteredScript> GetRegisteredStartupScripts () {
  590. if (_startupScriptBlocks == null)
  591. _startupScriptBlocks = new List<RegisteredScript> ();
  592. return new ReadOnlyCollection<RegisteredScript> (_startupScriptBlocks);
  593. }
  594. #if TARGET_J2EE
  595. bool _isMultiForm = false;
  596. bool _isMultiFormInited = false;
  597. bool IsMultiForm {
  598. get {
  599. if (!_isMultiFormInited) {
  600. string isMultiForm = WebConfigurationManager.AppSettings ["mainsoft.use.portlet.namespace"];
  601. _isMultiForm = isMultiForm != null ? Boolean.Parse (isMultiForm) : false;
  602. _isMultiFormInited = true;
  603. }
  604. return _isMultiForm;
  605. }
  606. }
  607. #else
  608. bool IsMultiForm {
  609. get { return false; }
  610. }
  611. #endif
  612. bool PanelRequiresUpdate (UpdatePanel panel)
  613. {
  614. if (panel == null || _panelsToRefresh == null || _panelsToRefresh.Count == 0)
  615. return false;
  616. return _panelsToRefresh.Contains (panel);
  617. }
  618. bool HasBeenRendered (Control control)
  619. {
  620. if (control == null)
  621. return false;
  622. UpdatePanel panel = control as UpdatePanel;
  623. if (PanelRequiresUpdate (panel))
  624. return true;
  625. return HasBeenRendered (control.Parent);
  626. }
  627. IEnumerable<ScriptReferenceEntry> GetScriptReferences () {
  628. if (_scripts != null && _scripts.Count > 0) {
  629. for (int i = 0; i < _scripts.Count; i++) {
  630. yield return new ScriptReferenceEntry (this, _scripts [i], LoadScriptsBeforeUI);
  631. }
  632. }
  633. if (_proxies != null && _proxies.Count > 0) {
  634. for (int i = 0; i < _proxies.Count; i++) {
  635. ScriptManagerProxy proxy = _proxies [i];
  636. for (int j = 0; j < proxy.Scripts.Count; j++)
  637. yield return new ScriptReferenceEntry (proxy, proxy.Scripts [j], LoadScriptsBeforeUI);
  638. }
  639. }
  640. if (_registeredScriptControls != null && _registeredScriptControls.Count > 0) {
  641. for (int i = 0; i < _registeredScriptControls.Count; i++) {
  642. IEnumerable<ScriptReference> scripts = _registeredScriptControls [i].GetScriptReferences ();
  643. if (scripts != null)
  644. foreach (ScriptReference s in scripts)
  645. yield return new ScriptReferenceEntry ((Control) _registeredScriptControls [i], s, LoadScriptsBeforeUI);
  646. }
  647. }
  648. if (_registeredExtenderControls != null && _registeredExtenderControls.Count > 0) {
  649. foreach (IExtenderControl ex in _registeredExtenderControls.Keys) {
  650. IEnumerable<ScriptReference> scripts = ex.GetScriptReferences ();
  651. if (scripts != null)
  652. foreach (ScriptReference s in scripts)
  653. yield return new ScriptReferenceEntry ((Control) ex, s, LoadScriptsBeforeUI);
  654. }
  655. }
  656. }
  657. protected virtual void OnResolveScriptReference (ScriptReferenceEventArgs e) {
  658. if (ResolveScriptReference != null)
  659. ResolveScriptReference (this, e);
  660. }
  661. protected virtual void RaisePostDataChangedEvent ()
  662. {
  663. // Why override?
  664. }
  665. public static void RegisterArrayDeclaration (Page page, string arrayName, string arrayValue) {
  666. RegisterArrayDeclaration ((Control) page, arrayName, arrayValue);
  667. }
  668. public static void RegisterArrayDeclaration (Control control, string arrayName, string arrayValue) {
  669. Page page = control.Page;
  670. ScriptManager sm = GetCurrentInternal (page);
  671. if (sm == null)
  672. return;
  673. if (sm._arrayDeclarations == null)
  674. sm._arrayDeclarations = new List<RegisteredArrayDeclaration> ();
  675. sm._arrayDeclarations.Add (new RegisteredArrayDeclaration (control, arrayName, arrayValue));
  676. if (!sm.IsInAsyncPostBack)
  677. page.ClientScript.RegisterArrayDeclaration (arrayName, arrayValue);
  678. }
  679. public void RegisterAsyncPostBackControl (Control control) {
  680. if (control == null)
  681. return;
  682. if (_asyncPostBackControls == null)
  683. _asyncPostBackControls = new List<Control> ();
  684. if (_asyncPostBackControls.Contains (control))
  685. return;
  686. _asyncPostBackControls.Add (control);
  687. }
  688. public static void RegisterClientScriptBlock (Page page, Type type, string key, string script, bool addScriptTags) {
  689. RegisterClientScriptBlock ((Control) page, type, key, script, addScriptTags);
  690. }
  691. public static void RegisterClientScriptBlock (Control control, Type type, string key, string script, bool addScriptTags) {
  692. Page page = control.Page;
  693. ScriptManager sm = GetCurrentInternal (page);
  694. if (sm == null)
  695. return;
  696. RegisterScript (ref sm._clientScriptBlocks, control, type, key, script, null, addScriptTags, RegisteredScriptType.ClientScriptBlock);
  697. if (!sm.IsInAsyncPostBack)
  698. page.ClientScript.RegisterClientScriptBlock (type, key, script, addScriptTags);
  699. }
  700. public static void RegisterClientScriptInclude (Page page, Type type, string key, string url) {
  701. RegisterClientScriptInclude ((Control) page, type, key, url);
  702. }
  703. public static void RegisterClientScriptInclude (Control control, Type type, string key, string url) {
  704. Page page = control.Page;
  705. ScriptManager sm = GetCurrentInternal (page);
  706. if (sm == null)
  707. return;
  708. RegisterScript (ref sm._clientScriptBlocks, control, type, key, null, url, false, RegisteredScriptType.ClientScriptInclude);
  709. if (!sm.IsInAsyncPostBack)
  710. page.ClientScript.RegisterClientScriptInclude (type, key, url);
  711. }
  712. public static void RegisterClientScriptResource (Page page, Type type, string resourceName) {
  713. RegisterClientScriptResource ((Control) page, type, resourceName);
  714. }
  715. public static void RegisterClientScriptResource (Control control, Type type, string resourceName) {
  716. RegisterClientScriptInclude (control, type, resourceName, ScriptResourceHandler.GetResourceUrl (type.Assembly, resourceName, true));
  717. }
  718. void RegisterScriptReference (Control control, ScriptReference script, bool loadScriptsBeforeUI)
  719. {
  720. string scriptPath = script.Path;
  721. string url = script.GetUrl (this, false);
  722. if (control != this && !String.IsNullOrEmpty (scriptPath))
  723. url = control.ResolveClientUrl (url);
  724. if (loadScriptsBeforeUI)
  725. RegisterClientScriptInclude (control, typeof (ScriptManager), url, url);
  726. else
  727. RegisterStartupScript (control, typeof (ScriptManager), url, String.Format ("<script src=\"{0}\" type=\"text/javascript\"></script>", url), false);
  728. }
  729. void RegisterServiceReference (Control control, ServiceReference serviceReference)
  730. {
  731. if (serviceReference.InlineScript) {
  732. string url = control.ResolveUrl (serviceReference.Path);
  733. Type type = WebServiceParser.GetCompiledType (url, Context);
  734. if (type != null) {
  735. object[] attributes = type.GetCustomAttributes (typeof (ScriptServiceAttribute), true);
  736. if (attributes.Length == 0)
  737. throw new InvalidOperationException ("Only Web services with a [ScriptService] attribute on the class definition can be called from script.");
  738. }
  739. LogicalTypeInfo logicalTypeInfo = LogicalTypeInfo.GetLogicalTypeInfo (type, url);
  740. RegisterClientScriptBlock (control, typeof (ScriptManager), url, logicalTypeInfo.Proxy, true);
  741. }
  742. else {
  743. #if TARGET_J2EE
  744. string pathInfo = "/js.invoke";
  745. #else
  746. string pathInfo = "/js";
  747. if (IsDebuggingEnabled)
  748. pathInfo += "debug";
  749. #endif
  750. string url = String.Concat (control.ResolveClientUrl (serviceReference.Path), pathInfo);
  751. RegisterClientScriptInclude (control, typeof (ScriptManager), url, url);
  752. }
  753. }
  754. public void RegisterDataItem (Control control, string dataItem) {
  755. RegisterDataItem (control, dataItem, false);
  756. }
  757. public void RegisterDataItem (Control control, string dataItem, bool isJsonSerialized) {
  758. if (!IsInAsyncPostBack)
  759. throw new InvalidOperationException ("RegisterDataItem can only be called during an async postback.");
  760. if (control == null)
  761. throw new ArgumentNullException ("control");
  762. if (_dataItems == null)
  763. _dataItems = new Dictionary<Control, DataItemEntry> ();
  764. if (_dataItems.ContainsKey (control))
  765. throw new ArgumentException (String.Format ("'{0}' already has a data item registered.", control.ID), "control");
  766. _dataItems.Add (control, new DataItemEntry (dataItem, isJsonSerialized));
  767. }
  768. public void RegisterDispose (Control control, string disposeScript) {
  769. if (control == null)
  770. throw new ArgumentNullException ("control");
  771. if (disposeScript == null)
  772. throw new ArgumentNullException ("disposeScript");
  773. UpdatePanel updatePanel = GetUpdatePanel (control);
  774. if (updatePanel == null)
  775. return;
  776. if (_disposeScripts == null)
  777. _disposeScripts = new List<RegisteredDisposeScript> ();
  778. _disposeScripts.Add (new RegisteredDisposeScript (control, disposeScript, updatePanel));
  779. }
  780. static UpdatePanel GetUpdatePanel (Control control) {
  781. if (control == null)
  782. return null;
  783. UpdatePanel parent = control.Parent as UpdatePanel;
  784. if (parent != null)
  785. return parent;
  786. return GetUpdatePanel (control.Parent);
  787. }
  788. public static void RegisterExpandoAttribute (Control control, string controlId, string attributeName, string attributeValue, bool encode) {
  789. Page page = control.Page;
  790. ScriptManager sm = GetCurrentInternal (page);
  791. if (sm == null)
  792. return;
  793. if (sm._expandoAttributes == null)
  794. sm._expandoAttributes = new List<RegisteredExpandoAttribute> ();
  795. sm._expandoAttributes.Add (new RegisteredExpandoAttribute (control, controlId, attributeName, attributeValue, encode));
  796. if (!sm.IsInAsyncPostBack)
  797. page.ClientScript.RegisterExpandoAttribute (controlId, attributeName, attributeValue, encode);
  798. }
  799. public static void RegisterHiddenField (Page page, string hiddenFieldName, string hiddenFieldInitialValue) {
  800. RegisterHiddenField ((Control) page, hiddenFieldName, hiddenFieldInitialValue);
  801. }
  802. public static void RegisterHiddenField (Control control, string hiddenFieldName, string hiddenFieldInitialValue) {
  803. Page page = control.Page;
  804. ScriptManager sm = GetCurrentInternal (page);
  805. if (sm == null)
  806. return;
  807. if (sm._hiddenFields == null)
  808. sm._hiddenFields = new List<RegisteredHiddenField> ();
  809. sm._hiddenFields.Add (new RegisteredHiddenField (control, hiddenFieldName, hiddenFieldInitialValue));
  810. if (!sm.IsInAsyncPostBack)
  811. page.ClientScript.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  812. }
  813. public static void RegisterOnSubmitStatement (Page page, Type type, string key, string script) {
  814. RegisterOnSubmitStatement ((Control) page, type, key, script);
  815. }
  816. public static void RegisterOnSubmitStatement (Control control, Type type, string key, string script) {
  817. Page page = control.Page;
  818. ScriptManager sm = GetCurrentInternal (page);
  819. if (sm == null)
  820. return;
  821. RegisterScript (ref sm._onSubmitStatements, control, type, key, script, null, false, RegisteredScriptType.OnSubmitStatement);
  822. if (!sm.IsInAsyncPostBack)
  823. page.ClientScript.RegisterOnSubmitStatement (type, key, script);
  824. }
  825. public void RegisterPostBackControl (Control control) {
  826. if (control == null)
  827. return;
  828. if (_postBackControls == null)
  829. _postBackControls = new List<Control> ();
  830. if (_postBackControls.Contains (control))
  831. return;
  832. _postBackControls.Add (control);
  833. }
  834. internal void RegisterUpdatePanel (UpdatePanel updatePanel) {
  835. if (_updatePanels == null)
  836. _updatePanels = new List<UpdatePanel> ();
  837. if (_updatePanels.Contains (updatePanel))
  838. return;
  839. _updatePanels.Add (updatePanel);
  840. }
  841. public void RegisterScriptDescriptors (IExtenderControl extenderControl) {
  842. if (extenderControl == null)
  843. return;
  844. if (_registeredExtenderControls == null || !_registeredExtenderControls.ContainsKey (extenderControl))
  845. return;
  846. Control targetControl = _registeredExtenderControls [extenderControl];
  847. RegisterScriptDescriptors ((Control) extenderControl, extenderControl.GetScriptDescriptors (targetControl));
  848. }
  849. public void RegisterScriptDescriptors (IScriptControl scriptControl) {
  850. if (scriptControl == null)
  851. return;
  852. if (_registeredScriptControls == null || !_registeredScriptControls.Contains (scriptControl))
  853. return;
  854. RegisterScriptDescriptors ((Control) scriptControl, scriptControl.GetScriptDescriptors ());
  855. }
  856. void RegisterScriptDescriptors (Control control, IEnumerable<ScriptDescriptor> scriptDescriptors)
  857. {
  858. if (scriptDescriptors == null)
  859. return;
  860. StringBuilder sb = new StringBuilder ();
  861. foreach (ScriptDescriptor scriptDescriptor in scriptDescriptors) {
  862. if (IsMultiForm) {
  863. scriptDescriptor.FormID = Page.Form.ClientID;
  864. sb.AppendLine ("Sys.Application.getInstance($get(\"" + Page.Form.ClientID + "\")).add_init(function() {");
  865. }
  866. else
  867. sb.AppendLine ("Sys.Application.add_init(function() {");
  868. sb.Append ("\t");
  869. sb.AppendLine (scriptDescriptor.GetScript ());
  870. sb.AppendLine ("});");
  871. }
  872. string script = sb.ToString ();
  873. RegisterStartupScript (control, typeof (ScriptDescriptor), script, script, true);
  874. }
  875. public static void RegisterStartupScript (Page page, Type type, string key, string script, bool addScriptTags) {
  876. RegisterStartupScript ((Control) page, type, key, script, addScriptTags);
  877. }
  878. public static void RegisterStartupScript (Control control, Type type, string key, string script, bool addScriptTags) {
  879. Page page = control.Page;
  880. ScriptManager sm = GetCurrentInternal (page);
  881. if (sm == null)
  882. return;
  883. RegisterScript (ref sm._startupScriptBlocks, control, type, key, script, null, addScriptTags, RegisteredScriptType.ClientStartupScript);
  884. if (!sm.IsInAsyncPostBack)
  885. page.ClientScript.RegisterStartupScript (type, key, script, addScriptTags);
  886. }
  887. public void RegisterScriptControl<TScriptControl> (TScriptControl scriptControl) where TScriptControl : Control, IScriptControl {
  888. if (scriptControl == null)
  889. throw new ArgumentNullException ("scriptControl");
  890. if (_registeredScriptControls == null)
  891. _registeredScriptControls = new List<IScriptControl> ();
  892. if (!_registeredScriptControls.Contains (scriptControl))
  893. _registeredScriptControls.Add (scriptControl);
  894. }
  895. public void RegisterExtenderControl<TExtenderControl> (TExtenderControl extenderControl, Control targetControl) where TExtenderControl : Control, IExtenderControl {
  896. if (extenderControl == null)
  897. throw new ArgumentNullException ("extenderControl");
  898. if (targetControl == null)
  899. throw new ArgumentNullException ("targetControl");
  900. if (_registeredExtenderControls == null)
  901. _registeredExtenderControls = new Dictionary<IExtenderControl, Control> ();
  902. if (!_registeredExtenderControls.ContainsKey (extenderControl))
  903. _registeredExtenderControls.Add (extenderControl, targetControl);
  904. }
  905. static void RegisterScript (ref List<RegisteredScript> scriptList, Control control, Type type, string key, string script, string url, bool addScriptTag, RegisteredScriptType scriptType) {
  906. if (scriptList == null)
  907. scriptList = new List<RegisteredScript> ();
  908. scriptList.Add (new RegisteredScript (control, type, key, script, url, addScriptTag, scriptType));
  909. }
  910. protected override void Render (HtmlTextWriter writer) {
  911. // MSDN: This method is used by control developers to extend the ScriptManager control.
  912. // Notes to Inheritors:
  913. // When overriding this method, call the base Render(HtmlTextWriter) method
  914. // so that PageRequestManager is rendered on the page.
  915. if (SupportsPartialRendering) {
  916. writer.WriteLine ("<script type=\"text/javascript\">");
  917. writer.WriteLine ("//<![CDATA[");
  918. writer.WriteLine ("Sys.WebForms.PageRequestManager._initialize('{0}', document.getElementById('{1}'));", UniqueID, Page.Form.ClientID);
  919. if (IsMultiForm)
  920. writer.WriteLine ("Sys.WebForms.PageRequestManager.getInstance($get(\"{0}\"))._updateControls([{1}], [{2}], [{3}], {4});",
  921. Page.Form.ClientID,
  922. FormatUpdatePanelIDs (_updatePanels, true),
  923. FormatListIDs (_asyncPostBackControls, true, false),
  924. FormatListIDs (_postBackControls, true, false),
  925. AsyncPostBackTimeout);
  926. else
  927. writer.WriteLine ("Sys.WebForms.PageRequestManager.getInstance()._updateControls([{0}], [{1}], [{2}], {3});",
  928. FormatUpdatePanelIDs (_updatePanels, true),
  929. FormatListIDs (_asyncPostBackControls, true, false),
  930. FormatListIDs (_postBackControls, true, false),
  931. AsyncPostBackTimeout);
  932. writer.WriteLine ("//]]");
  933. writer.WriteLine ("</script>");
  934. }
  935. base.Render (writer);
  936. }
  937. static string FormatUpdatePanelIDs (List<UpdatePanel> list, bool useSingleQuote) {
  938. if (list == null || list.Count == 0)
  939. return null;
  940. StringBuilder sb = new StringBuilder ();
  941. foreach (UpdatePanel panel in list) {
  942. if (!panel.Visible)
  943. continue;
  944. sb.AppendFormat ("{0}{1}{2}{0},", useSingleQuote ? "'" : String.Empty, panel.ChildrenAsTriggers ? "t" : "f", panel.UniqueID);
  945. }
  946. if (sb.Length > 0)
  947. sb.Length--;
  948. return sb.ToString ();
  949. }
  950. static string FormatListIDs<T> (List<T> list, bool useSingleQuote, bool skipInvisible) where T : Control
  951. {
  952. if (list == null || list.Count == 0)
  953. return null;
  954. StringBuilder sb = new StringBuilder ();
  955. for (int i = 0; i < list.Count; i++) {
  956. if (skipInvisible && !list [i].Visible)
  957. continue;
  958. sb.AppendFormat ("{0}{1}{0},", useSingleQuote ? "'" : String.Empty, list [i].UniqueID);
  959. }
  960. if (sb.Length > 0)
  961. sb.Length--;
  962. return sb.ToString ();
  963. }
  964. public void SetFocus (Control control) {
  965. if (control == null)
  966. throw new ArgumentNullException ("control");
  967. if (IsInAsyncPostBack) {
  968. EnsureFocusClientScript ();
  969. _controlIDToFocus = control.ClientID;
  970. }
  971. else
  972. Page.SetFocus (control);
  973. }
  974. public void SetFocus (string clientID) {
  975. if (String.IsNullOrEmpty (clientID))
  976. throw new ArgumentNullException ("control");
  977. if (IsInAsyncPostBack) {
  978. EnsureFocusClientScript ();
  979. _controlIDToFocus = clientID;
  980. }
  981. else
  982. Page.SetFocus (clientID);
  983. }
  984. void EnsureFocusClientScript () {
  985. #if TARGET_DOTNET
  986. RegisterClientScriptResource (this, typeof (ClientScriptManager), "Focus.js");
  987. #endif
  988. }
  989. #region IPostBackDataHandler Members
  990. bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection) {
  991. return LoadPostData (postDataKey, postCollection);
  992. }
  993. void IPostBackDataHandler.RaisePostDataChangedEvent () {
  994. RaisePostDataChangedEvent ();
  995. }
  996. #endregion
  997. internal void WriteCallbackException (TextWriter output, Exception ex, bool writeMessage) {
  998. #if TARGET_DOTNET
  999. if (ex is HttpUnhandledException)
  1000. ex = ex.InnerException;
  1001. #endif
  1002. HttpException httpEx = ex as HttpException;
  1003. string message = AsyncPostBackErrorMessage;
  1004. if (String.IsNullOrEmpty (message) && writeMessage) {
  1005. HttpContext ctx = HttpContext.Current;
  1006. if (IsDebuggingEnabled)
  1007. message = ex.ToString ();
  1008. else
  1009. message = ex.Message;
  1010. }
  1011. WriteCallbackOutput (output, error, httpEx == null ? "500" : httpEx.GetHttpCode ().ToString (), message);
  1012. }
  1013. static internal void WriteCallbackRedirect (TextWriter output, string redirectUrl) {
  1014. WriteCallbackOutput (output, pageRedirect, null, redirectUrl);
  1015. }
  1016. void RegisterPanelForRefresh (UpdatePanel panel)
  1017. {
  1018. if (_panelsToRefresh == null)
  1019. _panelsToRefresh = new List<UpdatePanel> ();
  1020. else if (_panelsToRefresh.Contains (panel))
  1021. return;
  1022. _panelsToRefresh.Add (panel);
  1023. }
  1024. internal void WriteCallbackPanel (TextWriter output, UpdatePanel panel, StringBuilder panelOutput)
  1025. {
  1026. WriteCallbackOutput (output, updatePanel, panel.ClientID, panelOutput);
  1027. }
  1028. internal void RegisterChildUpdatePanel (UpdatePanel updatePanel) {
  1029. if (_childUpdatePanels == null)
  1030. _childUpdatePanels = new List<UpdatePanel> ();
  1031. _childUpdatePanels.Add (updatePanel);
  1032. }
  1033. static void WriteCallbackOutput (TextWriter output, string type, string name, object value) {
  1034. string str = value as string;
  1035. StringBuilder sb = value as StringBuilder;
  1036. int length = 0;
  1037. if (str != null)
  1038. length = str.Length;
  1039. else if (sb != null)
  1040. length = sb.Length;
  1041. //output.Write ("{0}|{1}|{2}|{3}|", value == null ? 0 : value.Length, type, name, value);
  1042. output.Write (length);
  1043. output.Write ('|');
  1044. output.Write (type);
  1045. output.Write ('|');
  1046. output.Write (name);
  1047. output.Write ('|');
  1048. for (int i = 0; i < length; i++)
  1049. if (str != null)
  1050. output.Write (str [i]);
  1051. else
  1052. output.Write (sb [i]);
  1053. output.Write ('|');
  1054. }
  1055. void RenderPageCallback (HtmlTextWriter output, Control container)
  1056. {
  1057. Page page = (Page) container;
  1058. // MSDN: http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.aspx
  1059. //
  1060. // Refreshing UpdatePanel Content
  1061. //
  1062. // When partial-page rendering is enabled, a control can perform a postback
  1063. // that updates the whole page or an asynchronous postback that updates the
  1064. // content of one or more UpdatePanel controls. Whether a control causes an
  1065. // asynchronous postback and updates an UpdatePanel control depends on the
  1066. // following:
  1067. //
  1068. // * If the UpdateMode property of the UpdatePanel control is set to Always,
  1069. // the UpdatePanel control's content is updated on every postback that
  1070. // originates from the page. This includes asynchronous postbacks from
  1071. // controls that are inside other UpdatePanel controls and postbacks from
  1072. // controls that are not inside UpdatePanel controls.
  1073. //
  1074. // * If the UpdateMode property is set to Conditional, the UpdatePanel
  1075. // control's content is updated in the following circumstances:
  1076. //
  1077. // o When you call the Update method of the UpdatePanel control
  1078. // explicitly.
  1079. // o When the UpdatePanel control is nested inside another UpdatePanel
  1080. // control, and the parent panel is updated.
  1081. // o When a postback is caused by a control that is defined as a
  1082. // trigger by using the Triggers property of the UpdatePanel
  1083. // control. In this scenario, the control explicitly triggers an
  1084. // update of the panel content. The control can be either inside or
  1085. // outside the UpdatePanel control that the trigger is associated
  1086. // with.
  1087. // o When the ChildrenAsTriggers property is set to true and a child
  1088. // control of the UpdatePanel control causes a postback. Child
  1089. // controls of nested UpdatePanel controls do not cause an update to
  1090. // the outer UpdatePanel control unless they are explicitly defined
  1091. // as triggers.
  1092. //
  1093. if (_updatePanels != null && _updatePanels.Count > 0) {
  1094. bool needsUpdate;
  1095. foreach (UpdatePanel panel in _updatePanels) {
  1096. if (panel.RequiresUpdate || (!String.IsNullOrEmpty (_panelToRefreshID) && String.Compare (_panelToRefreshID, panel.UniqueID, StringComparison.Ordinal) == 0))
  1097. needsUpdate = true;
  1098. else
  1099. needsUpdate = false;
  1100. if (needsUpdate == false) {
  1101. Control parent = panel.Parent;
  1102. UpdatePanel parentPanel;
  1103. bool havePanelsToRefresh = _panelsToRefresh != null ? _panelsToRefresh.Count > 0 : false;
  1104. while (parent != null) {
  1105. parentPanel = parent as UpdatePanel;
  1106. if (havePanelsToRefresh && parentPanel != null && _panelsToRefresh.Contains (parentPanel)) {
  1107. needsUpdate = true;
  1108. break;
  1109. }
  1110. parent = parent.Parent;
  1111. }
  1112. }
  1113. panel.SetInPartialRendering (needsUpdate);
  1114. if (needsUpdate)
  1115. RegisterPanelForRefresh (panel);
  1116. }
  1117. }
  1118. page.Form.SetRenderMethodDelegate (RenderFormCallback);
  1119. HtmlTextParser parser = new HtmlTextParser (output);
  1120. page.Form.RenderControl (parser);
  1121. Dictionary <string, string> pageHiddenFields = parser.HiddenFields;
  1122. if (pageHiddenFields != null)
  1123. foreach (KeyValuePair <string, string> kvp in pageHiddenFields)
  1124. WriteCallbackOutput (output, hiddenField, kvp.Key, kvp.Value);
  1125. WriteCallbackOutput (output, asyncPostBackControlIDs, null, FormatListIDs (_asyncPostBackControls, false, false));
  1126. WriteCallbackOutput (output, postBackControlIDs, null, FormatListIDs (_postBackControls, false, false));
  1127. WriteCallbackOutput (output, updatePanelIDs, null, FormatUpdatePanelIDs (_updatePanels, false));
  1128. WriteCallbackOutput (output, childUpdatePanelIDs, null, FormatListIDs (_childUpdatePanels, false, true));
  1129. WriteCallbackOutput (output, panelsToRefreshIDs, null, FormatListIDs (_panelsToRefresh, false, true));
  1130. WriteCallbackOutput (output, asyncPostBackTimeout, null, AsyncPostBackTimeout.ToString ());
  1131. if (!IsMultiForm)
  1132. WriteCallbackOutput (output, pageTitle, null, Page.Title);
  1133. if (_dataItems != null)
  1134. foreach (Control control in _dataItems.Keys) {
  1135. DataItemEntry entry = _dataItems [control];
  1136. WriteCallbackOutput (output, entry.IsJsonSerialized ? dataItemJson : dataItem, control.ClientID, entry.DataItem);
  1137. }
  1138. WriteArrayDeclarations (output);
  1139. WriteExpandoAttributes (output);
  1140. WriteScriptBlocks (output, _clientScriptBlocks);
  1141. WriteScriptBlocks (output, _startupScriptBlocks);
  1142. WriteScriptBlocks (output, _onSubmitStatements);
  1143. WriteHiddenFields (output);
  1144. if (!String.IsNullOrEmpty (_controlIDToFocus))
  1145. WriteCallbackOutput (output, focus, null, _controlIDToFocus);
  1146. if (_disposeScripts != null)
  1147. for (int i = 0; i < _disposeScripts.Count; i++) {
  1148. RegisteredDisposeScript entry = _disposeScripts [i];
  1149. if ((_panelsToRefresh != null && _panelsToRefresh.IndexOf (entry.UpdatePanel) >= 0) || (_childUpdatePanels != null && _childUpdatePanels.IndexOf (entry.UpdatePanel) >= 0))
  1150. WriteCallbackOutput (output, scriptDispose, entry.UpdatePanel.ClientID, entry.Script);
  1151. }
  1152. }
  1153. private void WriteExpandoAttributes (HtmlTextWriter writer) {
  1154. if (_expandoAttributes != null) {
  1155. for (int i = 0; i < _expandoAttributes.Count; i++) {
  1156. RegisteredExpandoAttribute attr = _expandoAttributes [i];
  1157. if (HasBeenRendered (attr.Control)) {
  1158. string value;
  1159. if (attr.Encode) {
  1160. StringWriter sw = new StringWriter ();
  1161. Newtonsoft.Json.JavaScriptUtils.WriteEscapedJavaScriptString (attr.Value, sw);
  1162. value = sw.ToString ();
  1163. }
  1164. else
  1165. value = "\"" + attr.Value + "\"";
  1166. WriteCallbackOutput (writer, expando, "document.getElementById('" + attr.ControlId + "')['" + attr.Name + "']", value);
  1167. }
  1168. }
  1169. }
  1170. }
  1171. void WriteArrayDeclarations (HtmlTextWriter writer) {
  1172. if (_arrayDeclarations != null) {
  1173. for (int i = 0; i < _arrayDeclarations.Count; i++) {
  1174. RegisteredArrayDeclaration array = _arrayDeclarations [i];
  1175. if (Page == array.Control || HasBeenRendered (array.Control))
  1176. WriteCallbackOutput (writer, arrayDeclaration, array.Name, array.Value);
  1177. }
  1178. }
  1179. }
  1180. void WriteScriptBlocks (HtmlTextWriter output, List<RegisteredScript> scriptList) {
  1181. if (scriptList == null)
  1182. return;
  1183. var registeredScripts = new Dictionary <string, RegisteredScript> ();
  1184. Control control;
  1185. Page page = Page;
  1186. for (int i = 0; i < scriptList.Count; i++) {
  1187. RegisteredScript scriptEntry = scriptList [i];
  1188. if (registeredScripts.ContainsKey (scriptEntry.Key))
  1189. continue;
  1190. control = scriptEntry.Control;
  1191. if (page == control || HasBeenRendered (control)) {
  1192. registeredScripts.Add (scriptEntry.Key, scriptEntry);
  1193. switch (scriptEntry.ScriptType) {
  1194. case RegisteredScriptType.ClientScriptBlock:
  1195. if (scriptEntry.AddScriptTags)
  1196. WriteCallbackOutput (output, scriptBlock, scriptContentNoTags, scriptEntry.Script);
  1197. else
  1198. WriteCallbackOutput (output, scriptBlock, scriptContentWithTags, SerializeScriptBlock (scriptEntry));
  1199. break;
  1200. #if NET_3_5
  1201. case RegisteredScriptType.ClientStartupScript:
  1202. if (scriptEntry.AddScriptTags)
  1203. WriteCallbackOutput (output, scriptStartupBlock, scriptContentNoTags, scriptEntry.Script);
  1204. else
  1205. WriteCallbackOutput (output, scriptStartupBlock, scriptContentWithTags, SerializeScriptBlock (scriptEntry));
  1206. break;
  1207. #endif
  1208. case RegisteredScriptType.ClientScriptInclude:
  1209. WriteCallbackOutput (output, scriptBlock, scriptPath, scriptEntry.Url);
  1210. break;
  1211. case RegisteredScriptType.OnSubmitStatement:
  1212. WriteCallbackOutput (output, onSubmit, null, scriptEntry.Script);
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. void WriteHiddenFields (HtmlTextWriter output) {
  1219. if (_hiddenFields == null)
  1220. return;
  1221. Hashtable registeredFields = new Hashtable ();
  1222. for (int i = 0; i < _hiddenFields.Count; i++) {
  1223. RegisteredHiddenField field = _hiddenFields [i];
  1224. if (registeredFields.ContainsKey (field.Name))
  1225. continue;
  1226. if (Page == field.Control || HasBeenRendered (field.Control)) {
  1227. registeredFields.Add (field.Name, field);
  1228. WriteCallbackOutput (output, hiddenField, field.Name, field.InitialValue);
  1229. }
  1230. }
  1231. }
  1232. static string SerializeScriptBlock (RegisteredScript scriptEntry) {
  1233. try {
  1234. XmlTextReader reader = new XmlTextReader (new StringReader (scriptEntry.Script));
  1235. while (reader.Read ()) {
  1236. switch (reader.NodeType) {
  1237. case XmlNodeType.Element:
  1238. if (String.Compare ("script", reader.Name, StringComparison.OrdinalIgnoreCase) == 0) {
  1239. Dictionary<string, string> dic = new Dictionary<string, string> ();
  1240. while (reader.MoveToNextAttribute ()) {
  1241. dic.Add (reader.Name, reader.Value);
  1242. }
  1243. reader.MoveToContent ();
  1244. dic.Add ("text", reader.ReadInnerXml ());
  1245. return JavaScriptSerializer.DefaultSerializer.Serialize (dic);
  1246. }
  1247. break;
  1248. default:
  1249. continue;
  1250. }
  1251. }
  1252. }
  1253. catch {
  1254. }
  1255. 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.", scriptEntry.Type, scriptEntry.Key, scriptEntry.Script));
  1256. }
  1257. void RenderFormCallback (HtmlTextWriter output, Control container)
  1258. {
  1259. output = ((HtmlTextParser) output).ResponseOutput;
  1260. HtmlForm form = (HtmlForm) container;
  1261. HtmlTextWriter writer = new HtmlDropWriter (output);
  1262. if (form.HasControls ()) {
  1263. foreach (Control control in form.Controls)
  1264. control.RenderControl (writer);
  1265. }
  1266. }
  1267. internal class AlternativeHtmlTextWriter : HtmlTextWriter
  1268. {
  1269. readonly HtmlTextWriter _responseOutput;
  1270. public HtmlTextWriter ResponseOutput {
  1271. get { return _responseOutput; }
  1272. }
  1273. public AlternativeHtmlTextWriter (TextWriter writer, HtmlTextWriter responseOutput)
  1274. : base (writer) {
  1275. _responseOutput = responseOutput;
  1276. }
  1277. }
  1278. sealed class HtmlTextParser : AlternativeHtmlTextWriter
  1279. {
  1280. bool _done;
  1281. public Dictionary <string, string> _hiddenFields;
  1282. public Dictionary <string, string> HiddenFields {
  1283. get { return _hiddenFields; }
  1284. }
  1285. public HtmlTextParser (HtmlTextWriter responseOutput)
  1286. : this (new TextParser (responseOutput), responseOutput) {
  1287. }
  1288. HtmlTextParser (TextParser parser, HtmlTextWriter responseOutput)
  1289. : base (parser, responseOutput)
  1290. {
  1291. parser.HiddenFieldParsed += new TextParser.TextParserHiddenFieldParsedEventHandler (OnHiddenFieldParsed);
  1292. }
  1293. void OnHiddenFieldParsed (TextParser sender, TextParserHiddenFieldParsedEventArgs args)
  1294. {
  1295. if (_hiddenFields == null)
  1296. _hiddenFields = new Dictionary <string, string> ();
  1297. _hiddenFields [args.Name] = args.Value;
  1298. }
  1299. public override void WriteAttribute (string name, string value) {
  1300. if (!_done && String.Compare ("action", name, StringComparison.OrdinalIgnoreCase) == 0) {
  1301. _done = true;
  1302. ScriptManager.WriteCallbackOutput (ResponseOutput, formAction, null, value);
  1303. return;
  1304. }
  1305. base.WriteAttribute (name, value);
  1306. }
  1307. }
  1308. sealed class TextParserHiddenFieldParsedEventArgs : EventArgs
  1309. {
  1310. public string Name {
  1311. get;
  1312. private set;
  1313. }
  1314. public string Value {
  1315. get;
  1316. private set;
  1317. }
  1318. public TextParserHiddenFieldParsedEventArgs (string name, string value)
  1319. {
  1320. this.Name = name;
  1321. this.Value = value;
  1322. }
  1323. }
  1324. sealed class TextParser : TextWriter
  1325. {
  1326. public delegate void TextParserHiddenFieldParsedEventHandler (TextParser sender, TextParserHiddenFieldParsedEventArgs args);
  1327. static object textParserHiddenFieldParsedEvent = new object ();
  1328. int _state;
  1329. char _charState = (char) 255;
  1330. const char nullCharState = (char) 255;
  1331. StringBuilder _sb = new StringBuilder ();
  1332. Dictionary<string, string> _currentField;
  1333. string _currentAttribute;
  1334. readonly HtmlTextWriter _responseOutput;
  1335. TextParserHiddenFieldParsedEventHandler _hiddenFieldParsedHandler;
  1336. public event TextParserHiddenFieldParsedEventHandler HiddenFieldParsed {
  1337. add { _hiddenFieldParsedHandler = value; }
  1338. remove { _hiddenFieldParsedHandler = null; }
  1339. }
  1340. public override Encoding Encoding {
  1341. get { return Encoding.UTF8; }
  1342. }
  1343. public TextParser (HtmlTextWriter responseOutput) {
  1344. _responseOutput = responseOutput;
  1345. }
  1346. public override void Write (char value) {
  1347. switch (_state) {
  1348. case 0:
  1349. ParseBeginTag (value);
  1350. break;
  1351. case 1:
  1352. ParseAttributeName (value);
  1353. break;
  1354. case 2:
  1355. ParseAttributeValue (value);
  1356. break;
  1357. }
  1358. }
  1359. private void ParseAttributeValue (char value) {
  1360. switch (value) {
  1361. case '>':
  1362. ResetState ();
  1363. break;
  1364. case '"':
  1365. _currentField.Add (_currentAttribute, _sb.ToString ());
  1366. _state = 1;
  1367. _sb.Length = 0;
  1368. ProbeWriteOutput ();
  1369. break;
  1370. default:
  1371. _sb.Append (value);
  1372. break;
  1373. }
  1374. }
  1375. private void ParseAttributeName (char value) {
  1376. switch (value) {
  1377. case '>':
  1378. ResetState ();
  1379. break;
  1380. case ' ':
  1381. case '=':
  1382. break;
  1383. case '"':
  1384. _currentAttribute = _sb.ToString ();
  1385. _state = 2;
  1386. _sb.Length = 0;
  1387. break;
  1388. default:
  1389. _sb.Append (value);
  1390. break;
  1391. }
  1392. }
  1393. void ParseBeginTag (char value) {
  1394. switch (_charState) {
  1395. case nullCharState:
  1396. if (value == '<')
  1397. _charState = value;
  1398. break;
  1399. case '<':
  1400. if (value == 'i')
  1401. _charState = value;
  1402. else
  1403. ResetState ();
  1404. break;
  1405. case 'i':
  1406. if (value == 'n')
  1407. _charState = value;
  1408. else
  1409. ResetState ();
  1410. break;
  1411. case 'n':
  1412. if (value == 'p')
  1413. _charState = value;
  1414. else
  1415. ResetState ();
  1416. break;
  1417. case 'p':
  1418. if (value == 'u')
  1419. _charState = value;
  1420. else
  1421. ResetState ();
  1422. break;
  1423. case 'u':
  1424. if (value == 't')
  1425. _charState = value;
  1426. else
  1427. ResetState ();
  1428. break;
  1429. case 't':
  1430. if (value == ' ') {
  1431. _state = 1;
  1432. _currentField = new Dictionary<string, string> ();
  1433. }
  1434. else
  1435. ResetState ();
  1436. break;
  1437. }
  1438. }
  1439. private void ResetState () {
  1440. _charState = nullCharState;
  1441. _state = 0;
  1442. _sb.Length = 0;
  1443. }
  1444. private void ProbeWriteOutput () {
  1445. if (!_currentField.ContainsKey ("name"))
  1446. return;
  1447. if (!_currentField.ContainsKey ("value"))
  1448. return;
  1449. string value = _currentField ["value"];
  1450. if (value == null)
  1451. return;
  1452. if (_hiddenFieldParsedHandler != null)
  1453. _hiddenFieldParsedHandler (this, new TextParserHiddenFieldParsedEventArgs (_currentField ["name"], HttpUtility.HtmlDecode (value)));
  1454. else
  1455. ScriptManager.WriteCallbackOutput (_responseOutput, hiddenField, _currentField ["name"], HttpUtility.HtmlDecode (value));
  1456. }
  1457. }
  1458. sealed class HtmlDropWriter : AlternativeHtmlTextWriter
  1459. {
  1460. public HtmlDropWriter (HtmlTextWriter responseOutput)
  1461. : base (new DropWriter (), responseOutput) {
  1462. }
  1463. }
  1464. sealed class DropWriter : TextWriter
  1465. {
  1466. public override Encoding Encoding {
  1467. get { return Encoding.UTF8; }
  1468. }
  1469. }
  1470. sealed class CultureInfoSerializer
  1471. {
  1472. readonly CultureInfo _ci;
  1473. public CultureInfoSerializer (CultureInfo ci) {
  1474. if (ci == null)
  1475. throw new ArgumentNullException ("ci");
  1476. _ci = ci;
  1477. }
  1478. public string name {
  1479. get { return _ci.Name; }
  1480. }
  1481. public NumberFormatInfo numberFormat {
  1482. get { return _ci.NumberFormat; }
  1483. }
  1484. public DateTimeFormatInfo dateTimeFormat {
  1485. get { return _ci.DateTimeFormat; }
  1486. }
  1487. }
  1488. sealed class ScriptReferenceEntry
  1489. {
  1490. readonly Control _control;
  1491. readonly ScriptReference _scriptReference;
  1492. readonly bool _loadBeforeUI;
  1493. public Control Control { get { return _control; } }
  1494. public ScriptReference ScriptReference { get { return _scriptReference; } }
  1495. public bool LoadScriptsBeforeUI { get { return _loadBeforeUI; } }
  1496. public ScriptReferenceEntry (Control control, ScriptReference scriptReference, bool loadBeforeUI) {
  1497. _control = control;
  1498. _scriptReference = scriptReference;
  1499. _loadBeforeUI = loadBeforeUI;
  1500. }
  1501. }
  1502. sealed class DataItemEntry
  1503. {
  1504. readonly string _dataItem;
  1505. readonly bool _isJsonSerialized;
  1506. public string DataItem { get { return _dataItem; } }
  1507. public bool IsJsonSerialized { get { return _isJsonSerialized; } }
  1508. public DataItemEntry (string dataItem, bool isJsonSerialized) {
  1509. _dataItem = dataItem;
  1510. _isJsonSerialized = isJsonSerialized;
  1511. }
  1512. }
  1513. internal void RegisterProxy (ScriptManagerProxy scriptManagerProxy) {
  1514. if (_proxies == null)
  1515. _proxies = new List<ScriptManagerProxy> ();
  1516. _proxies.Add (scriptManagerProxy);
  1517. }
  1518. #region IScriptManager Members
  1519. void IScriptManager.RegisterOnSubmitStatementExternal (Control control, Type type, string key, string script) {
  1520. RegisterOnSubmitStatement (control, type, key, script);
  1521. }
  1522. void IScriptManager.RegisterExpandoAttributeExternal (Control control, string controlId, string attributeName, string attributeValue, bool encode) {
  1523. RegisterExpandoAttribute (control, controlId, attributeName, attributeValue, encode);
  1524. }
  1525. void IScriptManager.RegisterHiddenFieldExternal (Control control, string hiddenFieldName, string hiddenFieldInitialValue) {
  1526. RegisterHiddenField (control, hiddenFieldName, hiddenFieldInitialValue);
  1527. }
  1528. void IScriptManager.RegisterStartupScriptExternal (Control control, Type type, string key, string script, bool addScriptTags) {
  1529. RegisterStartupScript (control, type, key, script, addScriptTags);
  1530. }
  1531. void IScriptManager.RegisterArrayDeclarationExternal (Control control, string arrayName, string arrayValue) {
  1532. RegisterArrayDeclaration (control, arrayName, arrayValue);
  1533. }
  1534. void IScriptManager.RegisterClientScriptBlockExternal (Control control, Type type, string key, string script, bool addScriptTags) {
  1535. RegisterClientScriptBlock (control, type, key, script, addScriptTags);
  1536. }
  1537. void IScriptManager.RegisterClientScriptIncludeExternal (Control control, Type type, string key, string url) {
  1538. RegisterClientScriptInclude (control, type, key, url);
  1539. }
  1540. void IScriptManager.RegisterClientScriptResourceExternal (Control control, Type type, string resourceName) {
  1541. RegisterClientScriptResource (control, type, resourceName);
  1542. }
  1543. #endregion
  1544. }
  1545. }