2
0

ScriptManager.cs 59 KB

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