ScriptManager.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  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. 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. if (!String.IsNullOrEmpty (_panelToRefreshID)) {
  504. UpdatePanel panel = FindPanelWithId (_panelToRefreshID);
  505. if (panel != null)
  506. RegisterPanelForRefresh (panel);
  507. }
  508. // Register Scripts
  509. if (_scriptToRegister != null)
  510. for (int i = 0; i < _scriptToRegister.Count; i++)
  511. RegisterScriptReference (_scriptToRegister [i].Control, _scriptToRegister [i].ScriptReference, _scriptToRegister [i].LoadScriptsBeforeUI);
  512. if (!IsInAsyncPostBack) {
  513. // Register services
  514. if (_services != null && _services.Count > 0) {
  515. for (int i = 0; i < _services.Count; i++) {
  516. RegisterServiceReference (this, _services [i]);
  517. }
  518. }
  519. if (_proxies != null && _proxies.Count > 0) {
  520. for (int i = 0; i < _proxies.Count; i++) {
  521. ScriptManagerProxy proxy = _proxies [i];
  522. for (int j = 0; j < proxy.Services.Count; j++) {
  523. RegisterServiceReference (proxy, proxy.Services [j]);
  524. }
  525. }
  526. }
  527. if (EnablePageMethods) {
  528. LogicalTypeInfo logicalTypeInfo = LogicalTypeInfo.GetLogicalTypeInfo (Page.GetType (), Page.Request.FilePath);
  529. RegisterClientScriptBlock (this, typeof (ScriptManager), "PageMethods", logicalTypeInfo.Proxy, true);
  530. }
  531. // Register startup script
  532. if (IsMultiForm)
  533. RegisterStartupScript (this, typeof (ExtenderControl), "Sys.Application.initialize();", "Sys.Application.getInstance($get(\"" + Page.Form.ClientID + "\")).initialize();\n", true);
  534. else
  535. RegisterStartupScript (this, typeof (ExtenderControl), "Sys.Application.initialize();", "Sys.Application.initialize();\n", true);
  536. }
  537. }
  538. string GetProfileServicePath () {
  539. if (_profileService != null && !String.IsNullOrEmpty (_profileService.Path))
  540. return ResolveClientUrl (_profileService.Path);
  541. if (_proxies != null && _proxies.Count > 0)
  542. for (int i = 0; i < _proxies.Count; i++)
  543. if (!String.IsNullOrEmpty (_proxies [i].ProfileService.Path))
  544. return _proxies [i].ResolveClientUrl (_proxies [i].ProfileService.Path);
  545. return null;
  546. }
  547. string GetAuthenticationServicePath () {
  548. if (_authenticationService != null && !String.IsNullOrEmpty (_authenticationService.Path))
  549. return ResolveClientUrl (_authenticationService.Path);
  550. if (_proxies != null && _proxies.Count > 0)
  551. for (int i = 0; i < _proxies.Count; i++)
  552. if (!String.IsNullOrEmpty (_proxies [i].AuthenticationService.Path))
  553. return _proxies [i].ResolveClientUrl (_proxies [i].AuthenticationService.Path);
  554. return null;
  555. }
  556. public ReadOnlyCollection<RegisteredArrayDeclaration> GetRegisteredArrayDeclarations () {
  557. if (_arrayDeclarations == null)
  558. _arrayDeclarations = new List<RegisteredArrayDeclaration> ();
  559. return new ReadOnlyCollection<RegisteredArrayDeclaration> (_arrayDeclarations);
  560. }
  561. public ReadOnlyCollection<RegisteredScript> GetRegisteredClientScriptBlocks () {
  562. if (_clientScriptBlocks == null)
  563. _clientScriptBlocks = new List<RegisteredScript> ();
  564. return new ReadOnlyCollection<RegisteredScript> (_clientScriptBlocks);
  565. }
  566. public ReadOnlyCollection<RegisteredDisposeScript> GetRegisteredDisposeScripts () {
  567. if (_disposeScripts == null)
  568. _disposeScripts = new List<RegisteredDisposeScript> ();
  569. return new ReadOnlyCollection<RegisteredDisposeScript> (_disposeScripts);
  570. }
  571. public ReadOnlyCollection<RegisteredExpandoAttribute> GetRegisteredExpandoAttributes () {
  572. if (_expandoAttributes == null)
  573. _expandoAttributes = new List<RegisteredExpandoAttribute> ();
  574. return new ReadOnlyCollection<RegisteredExpandoAttribute> (_expandoAttributes);
  575. }
  576. public ReadOnlyCollection<RegisteredHiddenField> GetRegisteredHiddenFields () {
  577. if (_hiddenFields == null)
  578. _hiddenFields = new List<RegisteredHiddenField> ();
  579. return new ReadOnlyCollection<RegisteredHiddenField> (_hiddenFields);
  580. }
  581. public ReadOnlyCollection<RegisteredScript> GetRegisteredOnSubmitStatements () {
  582. if (_onSubmitStatements == null)
  583. _onSubmitStatements = new List<RegisteredScript> ();
  584. return new ReadOnlyCollection<RegisteredScript> (_onSubmitStatements);
  585. }
  586. public ReadOnlyCollection<RegisteredScript> GetRegisteredStartupScripts () {
  587. if (_startupScriptBlocks == null)
  588. _startupScriptBlocks = new List<RegisteredScript> ();
  589. return new ReadOnlyCollection<RegisteredScript> (_startupScriptBlocks);
  590. }
  591. #if TARGET_J2EE
  592. bool _isMultiForm = false;
  593. bool _isMultiFormInited = false;
  594. bool IsMultiForm {
  595. get {
  596. if (!_isMultiFormInited) {
  597. string isMultiForm = WebConfigurationManager.AppSettings ["mainsoft.use.portlet.namespace"];
  598. _isMultiForm = isMultiForm != null ? Boolean.Parse (isMultiForm) : false;
  599. _isMultiFormInited = true;
  600. }
  601. return _isMultiForm;
  602. }
  603. }
  604. #else
  605. bool IsMultiForm {
  606. get { return false; }
  607. }
  608. #endif
  609. static bool HasBeenRendered (Control control) {
  610. if (control == null)
  611. return false;
  612. UpdatePanel panel = control as UpdatePanel;
  613. if (panel != null && panel.RequiresUpdate)
  614. return true;
  615. return HasBeenRendered (control.Parent);
  616. }
  617. IEnumerable<ScriptReferenceEntry> GetScriptReferences () {
  618. if (_scripts != null && _scripts.Count > 0) {
  619. for (int i = 0; i < _scripts.Count; i++) {
  620. yield return new ScriptReferenceEntry (this, _scripts [i], LoadScriptsBeforeUI);
  621. }
  622. }
  623. if (_proxies != null && _proxies.Count > 0) {
  624. for (int i = 0; i < _proxies.Count; i++) {
  625. ScriptManagerProxy proxy = _proxies [i];
  626. for (int j = 0; j < proxy.Scripts.Count; j++)
  627. yield return new ScriptReferenceEntry (proxy, proxy.Scripts [j], LoadScriptsBeforeUI);
  628. }
  629. }
  630. if (_registeredScriptControls != null && _registeredScriptControls.Count > 0) {
  631. for (int i = 0; i < _registeredScriptControls.Count; i++) {
  632. IEnumerable<ScriptReference> scripts = _registeredScriptControls [i].GetScriptReferences ();
  633. if (scripts != null)
  634. foreach (ScriptReference s in scripts)
  635. yield return new ScriptReferenceEntry ((Control) _registeredScriptControls [i], s, LoadScriptsBeforeUI);
  636. }
  637. }
  638. if (_registeredExtenderControls != null && _registeredExtenderControls.Count > 0) {
  639. foreach (IExtenderControl ex in _registeredExtenderControls.Keys) {
  640. IEnumerable<ScriptReference> scripts = ex.GetScriptReferences ();
  641. if (scripts != null)
  642. foreach (ScriptReference s in scripts)
  643. yield return new ScriptReferenceEntry ((Control) ex, s, LoadScriptsBeforeUI);
  644. }
  645. }
  646. }
  647. protected virtual void OnResolveScriptReference (ScriptReferenceEventArgs e) {
  648. if (ResolveScriptReference != null)
  649. ResolveScriptReference (this, e);
  650. }
  651. protected virtual void RaisePostDataChangedEvent () {
  652. UpdatePanel up = Page.FindControl (_panelToRefreshID) as UpdatePanel;
  653. if (up != null && up.ChildrenAsTriggers)
  654. up.Update ();
  655. }
  656. public static void RegisterArrayDeclaration (Page page, string arrayName, string arrayValue) {
  657. RegisterArrayDeclaration ((Control) page, arrayName, arrayValue);
  658. }
  659. public static void RegisterArrayDeclaration (Control control, string arrayName, string arrayValue) {
  660. Page page = control.Page;
  661. ScriptManager sm = GetCurrent (page);
  662. if (sm._arrayDeclarations == null)
  663. sm._arrayDeclarations = new List<RegisteredArrayDeclaration> ();
  664. sm._arrayDeclarations.Add (new RegisteredArrayDeclaration (control, arrayName, arrayValue));
  665. if (!sm.IsInAsyncPostBack)
  666. page.ClientScript.RegisterArrayDeclaration (arrayName, arrayValue);
  667. }
  668. public void RegisterAsyncPostBackControl (Control control) {
  669. if (control == null)
  670. return;
  671. if (_asyncPostBackControls == null)
  672. _asyncPostBackControls = new List<Control> ();
  673. if (_asyncPostBackControls.Contains (control))
  674. return;
  675. _asyncPostBackControls.Add (control);
  676. }
  677. public static void RegisterClientScriptBlock (Page page, Type type, string key, string script, bool addScriptTags) {
  678. RegisterClientScriptBlock ((Control) page, type, key, script, addScriptTags);
  679. }
  680. public static void RegisterClientScriptBlock (Control control, Type type, string key, string script, bool addScriptTags) {
  681. Page page = control.Page;
  682. ScriptManager sm = GetCurrent (page);
  683. RegisterScript (ref sm._clientScriptBlocks, control, type, key, script, null, addScriptTags, RegisteredScriptType.ClientScriptBlock);
  684. if (!sm.IsInAsyncPostBack)
  685. page.ClientScript.RegisterClientScriptBlock (type, key, script, addScriptTags);
  686. }
  687. public static void RegisterClientScriptInclude (Page page, Type type, string key, string url) {
  688. RegisterClientScriptInclude ((Control) page, type, key, url);
  689. }
  690. public static void RegisterClientScriptInclude (Control control, Type type, string key, string url) {
  691. Page page = control.Page;
  692. ScriptManager sm = GetCurrent (page);
  693. RegisterScript (ref sm._clientScriptBlocks, control, type, key, null, url, false, RegisteredScriptType.ClientScriptInclude);
  694. if (!sm.IsInAsyncPostBack)
  695. page.ClientScript.RegisterClientScriptInclude (type, key, url);
  696. }
  697. public static void RegisterClientScriptResource (Page page, Type type, string resourceName) {
  698. RegisterClientScriptResource ((Control) page, type, resourceName);
  699. }
  700. public static void RegisterClientScriptResource (Control control, Type type, string resourceName) {
  701. RegisterClientScriptInclude (control, type, resourceName, ScriptResourceHandler.GetResourceUrl (type.Assembly, resourceName, true));
  702. }
  703. void RegisterScriptReference (Control control, ScriptReference script, bool loadScriptsBeforeUI) {
  704. bool isDebugMode = IsDeploymentRetail ? false : (script.ScriptModeInternal == ScriptMode.Inherit ? IsDebuggingEnabled : (script.ScriptModeInternal == ScriptMode.Debug));
  705. string url;
  706. if (!String.IsNullOrEmpty (script.Path)) {
  707. url = GetScriptName (control.ResolveClientUrl (script.Path), isDebugMode, EnableScriptLocalization ? script.ResourceUICultures : null);
  708. }
  709. else if (!String.IsNullOrEmpty (script.Name)) {
  710. Assembly assembly;
  711. if (String.IsNullOrEmpty (script.Assembly))
  712. assembly = typeof (ScriptManager).Assembly;
  713. else
  714. assembly = Assembly.Load (script.Assembly);
  715. string name = GetScriptName (script.Name, isDebugMode, null);
  716. if (script.IgnoreScriptPath || String.IsNullOrEmpty (ScriptPath))
  717. url = ScriptResourceHandler.GetResourceUrl (assembly, name, script.NotifyScriptLoaded);
  718. else {
  719. AssemblyName an = assembly.GetName ();
  720. url = ResolveClientUrl (String.Concat (VirtualPathUtility.AppendTrailingSlash (ScriptPath), an.Name, '/', an.Version, '/', name));
  721. }
  722. }
  723. else {
  724. throw new InvalidOperationException ("Name and Path cannot both be empty.");
  725. }
  726. if (loadScriptsBeforeUI)
  727. RegisterClientScriptInclude (control, typeof (ScriptManager), url, url);
  728. else
  729. RegisterStartupScript (control, typeof (ScriptManager), url, String.Format ("<script src=\"{0}\" type=\"text/javascript\"></script>", url), false);
  730. }
  731. static string GetScriptName (string releaseName, bool isDebugMode, string [] supportedUICultures) {
  732. if (!isDebugMode && (supportedUICultures == null || supportedUICultures.Length == 0))
  733. return releaseName;
  734. if (releaseName.Length < 3 || !releaseName.EndsWith (".js", StringComparison.OrdinalIgnoreCase))
  735. throw new InvalidOperationException (String.Format ("'{0}' is not a valid script path. The path must end in '.js'.", releaseName));
  736. StringBuilder sb = new StringBuilder (releaseName);
  737. sb.Length -= 3;
  738. if (isDebugMode)
  739. sb.Append (".debug");
  740. string culture = Thread.CurrentThread.CurrentUICulture.Name;
  741. if (supportedUICultures != null && Array.IndexOf<string> (supportedUICultures, culture) >= 0)
  742. sb.AppendFormat (".{0}", culture);
  743. sb.Append (".js");
  744. return sb.ToString ();
  745. }
  746. void RegisterServiceReference (Control control, ServiceReference serviceReference)
  747. {
  748. if (serviceReference.InlineScript) {
  749. string url = control.ResolveUrl (serviceReference.Path);
  750. Type type = WebServiceParser.GetCompiledType (url, Context);
  751. if (type != null) {
  752. object[] attributes = type.GetCustomAttributes (typeof (ScriptServiceAttribute), true);
  753. if (attributes.Length == 0)
  754. throw new InvalidOperationException ("Only Web services with a [ScriptService] attribute on the class definition can be called from script.");
  755. }
  756. LogicalTypeInfo logicalTypeInfo = LogicalTypeInfo.GetLogicalTypeInfo (type, url);
  757. RegisterClientScriptBlock (control, typeof (ScriptManager), url, logicalTypeInfo.Proxy, true);
  758. }
  759. else {
  760. #if TARGET_J2EE
  761. string pathInfo = "/js.invoke";
  762. #else
  763. string pathInfo = "/js";
  764. if (IsDebuggingEnabled)
  765. pathInfo += "debug";
  766. #endif
  767. string url = String.Concat (control.ResolveClientUrl (serviceReference.Path), pathInfo);
  768. RegisterClientScriptInclude (control, typeof (ScriptManager), url, url);
  769. }
  770. }
  771. public void RegisterDataItem (Control control, string dataItem) {
  772. RegisterDataItem (control, dataItem, false);
  773. }
  774. public void RegisterDataItem (Control control, string dataItem, bool isJsonSerialized) {
  775. if (!IsInAsyncPostBack)
  776. throw new InvalidOperationException ("RegisterDataItem can only be called during an async postback.");
  777. if (control == null)
  778. throw new ArgumentNullException ("control");
  779. if (_dataItems == null)
  780. _dataItems = new Dictionary<Control, DataItemEntry> ();
  781. if (_dataItems.ContainsKey (control))
  782. throw new ArgumentException (String.Format ("'{0}' already has a data item registered.", control.ID), "control");
  783. _dataItems.Add (control, new DataItemEntry (dataItem, isJsonSerialized));
  784. }
  785. public void RegisterDispose (Control control, string disposeScript) {
  786. if (control == null)
  787. throw new ArgumentNullException ("control");
  788. if (disposeScript == null)
  789. throw new ArgumentNullException ("disposeScript");
  790. UpdatePanel updatePanel = GetUpdatePanel (control);
  791. if (updatePanel == null)
  792. return;
  793. if (_disposeScripts == null)
  794. _disposeScripts = new List<RegisteredDisposeScript> ();
  795. _disposeScripts.Add (new RegisteredDisposeScript (control, disposeScript, updatePanel));
  796. }
  797. static UpdatePanel GetUpdatePanel (Control control) {
  798. if (control == null)
  799. return null;
  800. UpdatePanel parent = control.Parent as UpdatePanel;
  801. if (parent != null)
  802. return parent;
  803. return GetUpdatePanel (control.Parent);
  804. }
  805. public static void RegisterExpandoAttribute (Control control, string controlId, string attributeName, string attributeValue, bool encode) {
  806. Page page = control.Page;
  807. ScriptManager sm = GetCurrent (page);
  808. if (sm._expandoAttributes == null)
  809. sm._expandoAttributes = new List<RegisteredExpandoAttribute> ();
  810. sm._expandoAttributes.Add (new RegisteredExpandoAttribute (control, controlId, attributeName, attributeValue, encode));
  811. if (!sm.IsInAsyncPostBack)
  812. page.ClientScript.RegisterExpandoAttribute (controlId, attributeName, attributeValue, encode);
  813. }
  814. public static void RegisterHiddenField (Page page, string hiddenFieldName, string hiddenFieldInitialValue) {
  815. RegisterHiddenField ((Control) page, hiddenFieldName, hiddenFieldInitialValue);
  816. }
  817. public static void RegisterHiddenField (Control control, string hiddenFieldName, string hiddenFieldInitialValue) {
  818. Page page = control.Page;
  819. ScriptManager sm = GetCurrent (page);
  820. if (sm._hiddenFields == null)
  821. sm._hiddenFields = new List<RegisteredHiddenField> ();
  822. sm._hiddenFields.Add (new RegisteredHiddenField (control, hiddenFieldName, hiddenFieldInitialValue));
  823. if (!sm.IsInAsyncPostBack)
  824. page.ClientScript.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  825. }
  826. public static void RegisterOnSubmitStatement (Page page, Type type, string key, string script) {
  827. RegisterOnSubmitStatement ((Control) page, type, key, script);
  828. }
  829. public static void RegisterOnSubmitStatement (Control control, Type type, string key, string script) {
  830. Page page = control.Page;
  831. ScriptManager sm = GetCurrent (page);
  832. RegisterScript (ref sm._onSubmitStatements, control, type, key, script, null, false, RegisteredScriptType.OnSubmitStatement);
  833. if (!sm.IsInAsyncPostBack)
  834. page.ClientScript.RegisterOnSubmitStatement (type, key, script);
  835. }
  836. public void RegisterPostBackControl (Control control) {
  837. if (control == null)
  838. return;
  839. if (_postBackControls == null)
  840. _postBackControls = new List<Control> ();
  841. if (_postBackControls.Contains (control))
  842. return;
  843. _postBackControls.Add (control);
  844. }
  845. internal void RegisterUpdatePanel (UpdatePanel updatePanel) {
  846. if (_updatePanels == null)
  847. _updatePanels = new List<UpdatePanel> ();
  848. if (_updatePanels.Contains (updatePanel))
  849. return;
  850. _updatePanels.Add (updatePanel);
  851. }
  852. public void RegisterScriptDescriptors (IExtenderControl extenderControl) {
  853. if (extenderControl == null)
  854. return;
  855. if (_registeredExtenderControls == null || !_registeredExtenderControls.ContainsKey (extenderControl))
  856. return;
  857. Control targetControl = _registeredExtenderControls [extenderControl];
  858. RegisterScriptDescriptors ((Control) extenderControl, extenderControl.GetScriptDescriptors (targetControl));
  859. }
  860. public void RegisterScriptDescriptors (IScriptControl scriptControl) {
  861. if (scriptControl == null)
  862. return;
  863. if (_registeredScriptControls == null || !_registeredScriptControls.Contains (scriptControl))
  864. return;
  865. RegisterScriptDescriptors ((Control) scriptControl, scriptControl.GetScriptDescriptors ());
  866. }
  867. void RegisterScriptDescriptors (Control control, IEnumerable<ScriptDescriptor> scriptDescriptors) {
  868. if (scriptDescriptors == null)
  869. return;
  870. StringBuilder sb = new StringBuilder ();
  871. foreach (ScriptDescriptor scriptDescriptor in scriptDescriptors) {
  872. if (IsMultiForm) {
  873. scriptDescriptor.FormID = Page.Form.ClientID;
  874. sb.AppendLine ("Sys.Application.getInstance($get(\"" + Page.Form.ClientID + "\")).add_init(function() {");
  875. }
  876. else
  877. sb.AppendLine ("Sys.Application.add_init(function() {");
  878. sb.AppendLine (scriptDescriptor.GetScript ());
  879. sb.AppendLine ("});");
  880. }
  881. string script = sb.ToString ();
  882. RegisterStartupScript (control, typeof (ScriptDescriptor), script, script, true);
  883. }
  884. public static void RegisterStartupScript (Page page, Type type, string key, string script, bool addScriptTags) {
  885. RegisterStartupScript ((Control) page, type, key, script, addScriptTags);
  886. }
  887. public static void RegisterStartupScript (Control control, Type type, string key, string script, bool addScriptTags) {
  888. Page page = control.Page;
  889. ScriptManager sm = GetCurrent (page);
  890. RegisterScript (ref sm._startupScriptBlocks, control, type, key, script, null, addScriptTags, RegisteredScriptType.ClientStartupScript);
  891. if (!sm.IsInAsyncPostBack)
  892. page.ClientScript.RegisterStartupScript (type, key, script, addScriptTags);
  893. }
  894. public void RegisterScriptControl<TScriptControl> (TScriptControl scriptControl) where TScriptControl : Control, IScriptControl {
  895. if (scriptControl == null)
  896. throw new ArgumentNullException ("scriptControl");
  897. if (_registeredScriptControls == null)
  898. _registeredScriptControls = new List<IScriptControl> ();
  899. if (!_registeredScriptControls.Contains (scriptControl))
  900. _registeredScriptControls.Add (scriptControl);
  901. }
  902. public void RegisterExtenderControl<TExtenderControl> (TExtenderControl extenderControl, Control targetControl) where TExtenderControl : Control, IExtenderControl {
  903. if (extenderControl == null)
  904. throw new ArgumentNullException ("extenderControl");
  905. if (targetControl == null)
  906. throw new ArgumentNullException ("targetControl");
  907. if (_registeredExtenderControls == null)
  908. _registeredExtenderControls = new Dictionary<IExtenderControl, Control> ();
  909. if (!_registeredExtenderControls.ContainsKey (extenderControl))
  910. _registeredExtenderControls.Add (extenderControl, targetControl);
  911. }
  912. static void RegisterScript (ref List<RegisteredScript> scriptList, Control control, Type type, string key, string script, string url, bool addScriptTag, RegisteredScriptType scriptType) {
  913. if (scriptList == null)
  914. scriptList = new List<RegisteredScript> ();
  915. scriptList.Add (new RegisteredScript (control, type, key, script, url, addScriptTag, scriptType));
  916. }
  917. protected override void Render (HtmlTextWriter writer) {
  918. // MSDN: This method is used by control developers to extend the ScriptManager control.
  919. // Notes to Inheritors:
  920. // When overriding this method, call the base Render(HtmlTextWriter) method
  921. // so that PageRequestManager is rendered on the page.
  922. if (SupportsPartialRendering) {
  923. writer.WriteLine ("<script type=\"text/javascript\">");
  924. writer.WriteLine ("//<![CDATA[");
  925. writer.WriteLine ("Sys.WebForms.PageRequestManager._initialize('{0}', document.getElementById('{1}'));", UniqueID, Page.Form.ClientID);
  926. if (IsMultiForm)
  927. writer.WriteLine ("Sys.WebForms.PageRequestManager.getInstance($get(\"{0}\"))._updateControls([{1}], [{2}], [{3}], {4});", Page.Form.ClientID, FormatUpdatePanelIDs (_updatePanels, true), FormatListIDs (_asyncPostBackControls, true), FormatListIDs (_postBackControls, true), AsyncPostBackTimeout);
  928. else
  929. writer.WriteLine ("Sys.WebForms.PageRequestManager.getInstance()._updateControls([{0}], [{1}], [{2}], {3});", FormatUpdatePanelIDs (_updatePanels, true), FormatListIDs (_asyncPostBackControls, true), FormatListIDs (_postBackControls, true), AsyncPostBackTimeout);
  930. writer.WriteLine ("//]]");
  931. writer.WriteLine ("</script>");
  932. }
  933. base.Render (writer);
  934. }
  935. static string FormatUpdatePanelIDs (List<UpdatePanel> list, bool useSingleQuote) {
  936. if (list == null || list.Count == 0)
  937. return null;
  938. StringBuilder sb = new StringBuilder ();
  939. for (int i = 0; i < list.Count; i++) {
  940. sb.AppendFormat ("{0}{1}{2}{0},", useSingleQuote ? "'" : String.Empty, list [i].ChildrenAsTriggers ? "t" : "f", list [i].UniqueID);
  941. }
  942. if (sb.Length > 0)
  943. sb.Length--;
  944. return sb.ToString ();
  945. }
  946. static string FormatListIDs<T> (List<T> list, bool useSingleQuote) where T : Control {
  947. if (list == null || list.Count == 0)
  948. return null;
  949. StringBuilder sb = new StringBuilder ();
  950. for (int i = 0; i < list.Count; i++) {
  951. sb.AppendFormat ("{0}{1}{0},", useSingleQuote ? "'" : String.Empty, list [i].UniqueID);
  952. }
  953. if (sb.Length > 0)
  954. sb.Length--;
  955. return sb.ToString ();
  956. }
  957. public void SetFocus (Control control) {
  958. if (control == null)
  959. throw new ArgumentNullException ("control");
  960. if (IsInAsyncPostBack) {
  961. EnsureFocusClientScript ();
  962. _controlIDToFocus = control.ClientID;
  963. }
  964. else
  965. Page.SetFocus (control);
  966. }
  967. public void SetFocus (string clientID) {
  968. if (String.IsNullOrEmpty (clientID))
  969. throw new ArgumentNullException ("control");
  970. if (IsInAsyncPostBack) {
  971. EnsureFocusClientScript ();
  972. _controlIDToFocus = clientID;
  973. }
  974. else
  975. Page.SetFocus (clientID);
  976. }
  977. void EnsureFocusClientScript () {
  978. #if TARGET_DOTNET
  979. RegisterClientScriptResource (this, typeof (ClientScriptManager), "Focus.js");
  980. #endif
  981. }
  982. #region IPostBackDataHandler Members
  983. bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection) {
  984. return LoadPostData (postDataKey, postCollection);
  985. }
  986. void IPostBackDataHandler.RaisePostDataChangedEvent () {
  987. RaisePostDataChangedEvent ();
  988. }
  989. #endregion
  990. internal void WriteCallbackException (TextWriter output, Exception ex, bool writeMessage) {
  991. #if TARGET_DOTNET
  992. if (ex is HttpUnhandledException)
  993. ex = ex.InnerException;
  994. #endif
  995. HttpException httpEx = ex as HttpException;
  996. string message = AsyncPostBackErrorMessage;
  997. if (String.IsNullOrEmpty (message) && writeMessage) {
  998. HttpContext ctx = HttpContext.Current;
  999. if (IsDebuggingEnabled)
  1000. message = ex.ToString ();
  1001. else
  1002. message = ex.Message;
  1003. }
  1004. WriteCallbackOutput (output, error, httpEx == null ? "500" : httpEx.GetHttpCode ().ToString (), message);
  1005. }
  1006. static internal void WriteCallbackRedirect (TextWriter output, string redirectUrl) {
  1007. WriteCallbackOutput (output, pageRedirect, null, redirectUrl);
  1008. }
  1009. void RegisterPanelForRefresh (UpdatePanel panel)
  1010. {
  1011. if (_panelsToRefresh == null)
  1012. _panelsToRefresh = new List<UpdatePanel> ();
  1013. else if (_panelsToRefresh.Contains (panel))
  1014. return;
  1015. panel.Update ();
  1016. _panelsToRefresh.Add (panel);
  1017. }
  1018. internal void WriteCallbackPanel (TextWriter output, UpdatePanel panel, StringBuilder panelOutput) {
  1019. RegisterPanelForRefresh (panel);
  1020. WriteCallbackOutput (output, updatePanel, panel.ClientID, panelOutput);
  1021. }
  1022. internal void RegisterChildUpdatePanel (UpdatePanel updatePanel) {
  1023. if (_childUpdatePanels == null)
  1024. _childUpdatePanels = new List<UpdatePanel> ();
  1025. _childUpdatePanels.Add (updatePanel);
  1026. }
  1027. static void WriteCallbackOutput (TextWriter output, string type, string name, object value) {
  1028. string str = value as string;
  1029. StringBuilder sb = value as StringBuilder;
  1030. int length = 0;
  1031. if (str != null)
  1032. length = str.Length;
  1033. else if (sb != null)
  1034. length = sb.Length;
  1035. //output.Write ("{0}|{1}|{2}|{3}|", value == null ? 0 : value.Length, type, name, value);
  1036. output.Write (length);
  1037. output.Write ('|');
  1038. output.Write (type);
  1039. output.Write ('|');
  1040. output.Write (name);
  1041. output.Write ('|');
  1042. for (int i = 0; i < length; i++)
  1043. if (str != null)
  1044. output.Write (str [i]);
  1045. else
  1046. output.Write (sb [i]);
  1047. output.Write ('|');
  1048. }
  1049. void RenderPageCallback (HtmlTextWriter output, Control container) {
  1050. Page page = (Page) container;
  1051. page.Form.SetRenderMethodDelegate (RenderFormCallback);
  1052. HtmlTextParser parser = new HtmlTextParser (output);
  1053. page.Form.RenderControl (parser);
  1054. Dictionary <string, string> pageHiddenFields = parser.HiddenFields;
  1055. if (pageHiddenFields != null)
  1056. foreach (KeyValuePair <string, string> kvp in pageHiddenFields)
  1057. WriteCallbackOutput (output, hiddenField, kvp.Key, kvp.Value);
  1058. WriteCallbackOutput (output, asyncPostBackControlIDs, null, FormatListIDs (_asyncPostBackControls, false));
  1059. WriteCallbackOutput (output, postBackControlIDs, null, FormatListIDs (_postBackControls, false));
  1060. WriteCallbackOutput (output, updatePanelIDs, null, FormatUpdatePanelIDs (_updatePanels, false));
  1061. WriteCallbackOutput (output, childUpdatePanelIDs, null, FormatListIDs (_childUpdatePanels, false));
  1062. WriteCallbackOutput (output, panelsToRefreshIDs, null, FormatListIDs (_panelsToRefresh, false));
  1063. WriteCallbackOutput (output, asyncPostBackTimeout, null, AsyncPostBackTimeout.ToString ());
  1064. if (!IsMultiForm)
  1065. WriteCallbackOutput (output, pageTitle, null, Page.Title);
  1066. if (_dataItems != null)
  1067. foreach (Control control in _dataItems.Keys) {
  1068. DataItemEntry entry = _dataItems [control];
  1069. WriteCallbackOutput (output, entry.IsJsonSerialized ? dataItemJson : dataItem, control.ClientID, entry.DataItem);
  1070. }
  1071. WriteArrayDeclarations (output);
  1072. WriteExpandoAttributes (output);
  1073. WriteScriptBlocks (output, _clientScriptBlocks);
  1074. WriteScriptBlocks (output, _startupScriptBlocks);
  1075. WriteScriptBlocks (output, _onSubmitStatements);
  1076. WriteHiddenFields (output);
  1077. if (!String.IsNullOrEmpty (_controlIDToFocus))
  1078. WriteCallbackOutput (output, focus, null, _controlIDToFocus);
  1079. if (_disposeScripts != null)
  1080. for (int i = 0; i < _disposeScripts.Count; i++) {
  1081. RegisteredDisposeScript entry = _disposeScripts [i];
  1082. if ((_panelsToRefresh != null && _panelsToRefresh.IndexOf (entry.UpdatePanel) >= 0) || (_childUpdatePanels != null && _childUpdatePanels.IndexOf (entry.UpdatePanel) >= 0))
  1083. WriteCallbackOutput (output, scriptDispose, entry.UpdatePanel.ClientID, entry.Script);
  1084. }
  1085. }
  1086. private void WriteExpandoAttributes (HtmlTextWriter writer) {
  1087. if (_expandoAttributes != null) {
  1088. for (int i = 0; i < _expandoAttributes.Count; i++) {
  1089. RegisteredExpandoAttribute attr = _expandoAttributes [i];
  1090. if (HasBeenRendered (attr.Control)) {
  1091. string value;
  1092. if (attr.Encode) {
  1093. StringWriter sw = new StringWriter ();
  1094. Newtonsoft.Json.JavaScriptUtils.WriteEscapedJavaScriptString (attr.Value, sw);
  1095. value = sw.ToString ();
  1096. }
  1097. else
  1098. value = "\"" + attr.Value + "\"";
  1099. WriteCallbackOutput (writer, expando, "document.getElementById('" + attr.ControlId + "')['" + attr.Name + "']", value);
  1100. }
  1101. }
  1102. }
  1103. }
  1104. void WriteArrayDeclarations (HtmlTextWriter writer) {
  1105. if (_arrayDeclarations != null) {
  1106. for (int i = 0; i < _arrayDeclarations.Count; i++) {
  1107. RegisteredArrayDeclaration array = _arrayDeclarations [i];
  1108. if (Page == array.Control || HasBeenRendered (array.Control))
  1109. WriteCallbackOutput (writer, arrayDeclaration, array.Name, array.Value);
  1110. }
  1111. }
  1112. }
  1113. void WriteScriptBlocks (HtmlTextWriter output, List<RegisteredScript> scriptList) {
  1114. if (scriptList == null)
  1115. return;
  1116. var registeredScripts = new Dictionary <string, RegisteredScript> ();
  1117. Control control;
  1118. for (int i = 0; i < scriptList.Count; i++) {
  1119. RegisteredScript scriptEntry = scriptList [i];
  1120. if (registeredScripts.ContainsKey (scriptEntry.Key))
  1121. continue;
  1122. control = scriptEntry.Control;
  1123. if (Page == control || HasBeenRendered (control)) {
  1124. registeredScripts.Add (scriptEntry.Key, scriptEntry);
  1125. switch (scriptEntry.ScriptType) {
  1126. case RegisteredScriptType.ClientScriptBlock:
  1127. if (scriptEntry.AddScriptTags)
  1128. WriteCallbackOutput (output, scriptBlock, scriptContentNoTags, scriptEntry.Script);
  1129. else
  1130. WriteCallbackOutput (output, scriptBlock, scriptContentWithTags, SerializeScriptBlock (scriptEntry));
  1131. break;
  1132. case RegisteredScriptType.ClientStartupScript:
  1133. if (scriptEntry.AddScriptTags)
  1134. WriteCallbackOutput (output, scriptStartupBlock, scriptContentNoTags, scriptEntry.Script);
  1135. else
  1136. WriteCallbackOutput (output, scriptStartupBlock, scriptContentWithTags, SerializeScriptBlock (scriptEntry));
  1137. break;
  1138. case RegisteredScriptType.ClientScriptInclude:
  1139. WriteCallbackOutput (output, scriptBlock, scriptPath, scriptEntry.Url);
  1140. break;
  1141. case RegisteredScriptType.OnSubmitStatement:
  1142. WriteCallbackOutput (output, onSubmit, null, scriptEntry.Script);
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. void WriteHiddenFields (HtmlTextWriter output) {
  1149. if (_hiddenFields == null)
  1150. return;
  1151. Hashtable registeredFields = new Hashtable ();
  1152. for (int i = 0; i < _hiddenFields.Count; i++) {
  1153. RegisteredHiddenField field = _hiddenFields [i];
  1154. if (registeredFields.ContainsKey (field.Name))
  1155. continue;
  1156. if (Page == field.Control || HasBeenRendered (field.Control)) {
  1157. registeredFields.Add (field.Name, field);
  1158. WriteCallbackOutput (output, hiddenField, field.Name, field.InitialValue);
  1159. }
  1160. }
  1161. }
  1162. static string SerializeScriptBlock (RegisteredScript scriptEntry) {
  1163. try {
  1164. XmlTextReader reader = new XmlTextReader (new StringReader (scriptEntry.Script));
  1165. while (reader.Read ()) {
  1166. switch (reader.NodeType) {
  1167. case XmlNodeType.Element:
  1168. if (String.Compare ("script", reader.Name, StringComparison.OrdinalIgnoreCase) == 0) {
  1169. Dictionary<string, string> dic = new Dictionary<string, string> ();
  1170. while (reader.MoveToNextAttribute ()) {
  1171. dic.Add (reader.Name, reader.Value);
  1172. }
  1173. reader.MoveToContent ();
  1174. dic.Add ("text", reader.ReadInnerXml ());
  1175. return JavaScriptSerializer.DefaultSerializer.Serialize (dic);
  1176. }
  1177. break;
  1178. default:
  1179. continue;
  1180. }
  1181. }
  1182. }
  1183. catch {
  1184. }
  1185. 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));
  1186. }
  1187. void RenderFormCallback (HtmlTextWriter output, Control container) {
  1188. output = ((HtmlTextParser) output).ResponseOutput;
  1189. HtmlForm form = (HtmlForm) container;
  1190. HtmlTextWriter writer = new HtmlDropWriter (output);
  1191. if (form.HasControls ()) {
  1192. for (int i = 0; i < form.Controls.Count; i++) {
  1193. form.Controls [i].RenderControl (writer);
  1194. }
  1195. }
  1196. }
  1197. internal class AlternativeHtmlTextWriter : HtmlTextWriter
  1198. {
  1199. readonly HtmlTextWriter _responseOutput;
  1200. public HtmlTextWriter ResponseOutput {
  1201. get { return _responseOutput; }
  1202. }
  1203. public AlternativeHtmlTextWriter (TextWriter writer, HtmlTextWriter responseOutput)
  1204. : base (writer) {
  1205. _responseOutput = responseOutput;
  1206. }
  1207. }
  1208. sealed class HtmlTextParser : AlternativeHtmlTextWriter
  1209. {
  1210. bool _done;
  1211. public Dictionary <string, string> _hiddenFields;
  1212. public Dictionary <string, string> HiddenFields {
  1213. get { return _hiddenFields; }
  1214. }
  1215. public HtmlTextParser (HtmlTextWriter responseOutput)
  1216. : this (new TextParser (responseOutput), responseOutput) {
  1217. }
  1218. HtmlTextParser (TextParser parser, HtmlTextWriter responseOutput)
  1219. : base (parser, responseOutput)
  1220. {
  1221. parser.HiddenFieldParsed += new TextParser.TextParserHiddenFieldParsedEventHandler (OnHiddenFieldParsed);
  1222. }
  1223. void OnHiddenFieldParsed (TextParser sender, TextParserHiddenFieldParsedEventArgs args)
  1224. {
  1225. if (_hiddenFields == null)
  1226. _hiddenFields = new Dictionary <string, string> ();
  1227. _hiddenFields [args.Name] = args.Value;
  1228. }
  1229. public override void WriteAttribute (string name, string value) {
  1230. if (!_done && String.Compare ("action", name, StringComparison.OrdinalIgnoreCase) == 0) {
  1231. _done = true;
  1232. ScriptManager.WriteCallbackOutput (ResponseOutput, formAction, null, value);
  1233. return;
  1234. }
  1235. base.WriteAttribute (name, value);
  1236. }
  1237. }
  1238. sealed class TextParserHiddenFieldParsedEventArgs : EventArgs
  1239. {
  1240. public string Name {
  1241. get;
  1242. private set;
  1243. }
  1244. public string Value {
  1245. get;
  1246. private set;
  1247. }
  1248. public TextParserHiddenFieldParsedEventArgs (string name, string value)
  1249. {
  1250. this.Name = name;
  1251. this.Value = value;
  1252. }
  1253. }
  1254. sealed class TextParser : TextWriter
  1255. {
  1256. public delegate void TextParserHiddenFieldParsedEventHandler (TextParser sender, TextParserHiddenFieldParsedEventArgs args);
  1257. static object textParserHiddenFieldParsedEvent = new object ();
  1258. int _state;
  1259. char _charState = (char) 255;
  1260. const char nullCharState = (char) 255;
  1261. StringBuilder _sb = new StringBuilder ();
  1262. Dictionary<string, string> _currentField;
  1263. string _currentAttribute;
  1264. readonly HtmlTextWriter _responseOutput;
  1265. TextParserHiddenFieldParsedEventHandler _hiddenFieldParsedHandler;
  1266. public event TextParserHiddenFieldParsedEventHandler HiddenFieldParsed {
  1267. add { _hiddenFieldParsedHandler = value; }
  1268. remove { _hiddenFieldParsedHandler = null; }
  1269. }
  1270. public override Encoding Encoding {
  1271. get { return Encoding.UTF8; }
  1272. }
  1273. public TextParser (HtmlTextWriter responseOutput) {
  1274. _responseOutput = responseOutput;
  1275. }
  1276. public override void Write (char value) {
  1277. switch (_state) {
  1278. case 0:
  1279. ParseBeginTag (value);
  1280. break;
  1281. case 1:
  1282. ParseAttributeName (value);
  1283. break;
  1284. case 2:
  1285. ParseAttributeValue (value);
  1286. break;
  1287. }
  1288. }
  1289. private void ParseAttributeValue (char value) {
  1290. switch (value) {
  1291. case '>':
  1292. ResetState ();
  1293. break;
  1294. case '"':
  1295. _currentField.Add (_currentAttribute, _sb.ToString ());
  1296. _state = 1;
  1297. _sb.Length = 0;
  1298. ProbeWriteOutput ();
  1299. break;
  1300. default:
  1301. _sb.Append (value);
  1302. break;
  1303. }
  1304. }
  1305. private void ParseAttributeName (char value) {
  1306. switch (value) {
  1307. case '>':
  1308. ResetState ();
  1309. break;
  1310. case ' ':
  1311. case '=':
  1312. break;
  1313. case '"':
  1314. _currentAttribute = _sb.ToString ();
  1315. _state = 2;
  1316. _sb.Length = 0;
  1317. break;
  1318. default:
  1319. _sb.Append (value);
  1320. break;
  1321. }
  1322. }
  1323. void ParseBeginTag (char value) {
  1324. switch (_charState) {
  1325. case nullCharState:
  1326. if (value == '<')
  1327. _charState = value;
  1328. break;
  1329. case '<':
  1330. if (value == 'i')
  1331. _charState = value;
  1332. else
  1333. ResetState ();
  1334. break;
  1335. case 'i':
  1336. if (value == 'n')
  1337. _charState = value;
  1338. else
  1339. ResetState ();
  1340. break;
  1341. case 'n':
  1342. if (value == 'p')
  1343. _charState = value;
  1344. else
  1345. ResetState ();
  1346. break;
  1347. case 'p':
  1348. if (value == 'u')
  1349. _charState = value;
  1350. else
  1351. ResetState ();
  1352. break;
  1353. case 'u':
  1354. if (value == 't')
  1355. _charState = value;
  1356. else
  1357. ResetState ();
  1358. break;
  1359. case 't':
  1360. if (value == ' ') {
  1361. _state = 1;
  1362. _currentField = new Dictionary<string, string> ();
  1363. }
  1364. else
  1365. ResetState ();
  1366. break;
  1367. }
  1368. }
  1369. private void ResetState () {
  1370. _charState = nullCharState;
  1371. _state = 0;
  1372. _sb.Length = 0;
  1373. }
  1374. private void ProbeWriteOutput () {
  1375. if (!_currentField.ContainsKey ("name"))
  1376. return;
  1377. if (!_currentField.ContainsKey ("value"))
  1378. return;
  1379. string value = _currentField ["value"];
  1380. if (value == null)
  1381. return;
  1382. if (_hiddenFieldParsedHandler != null)
  1383. _hiddenFieldParsedHandler (this, new TextParserHiddenFieldParsedEventArgs (_currentField ["name"], HttpUtility.HtmlDecode (value)));
  1384. else
  1385. ScriptManager.WriteCallbackOutput (_responseOutput, hiddenField, _currentField ["name"], HttpUtility.HtmlDecode (value));
  1386. }
  1387. }
  1388. sealed class HtmlDropWriter : AlternativeHtmlTextWriter
  1389. {
  1390. public HtmlDropWriter (HtmlTextWriter responseOutput)
  1391. : base (new DropWriter (), responseOutput) {
  1392. }
  1393. }
  1394. sealed class DropWriter : TextWriter
  1395. {
  1396. public override Encoding Encoding {
  1397. get { return Encoding.UTF8; }
  1398. }
  1399. }
  1400. sealed class CultureInfoSerializer
  1401. {
  1402. readonly CultureInfo _ci;
  1403. public CultureInfoSerializer (CultureInfo ci) {
  1404. if (ci == null)
  1405. throw new ArgumentNullException ("ci");
  1406. _ci = ci;
  1407. }
  1408. public string name {
  1409. get { return _ci.Name; }
  1410. }
  1411. public NumberFormatInfo numberFormat {
  1412. get { return _ci.NumberFormat; }
  1413. }
  1414. public DateTimeFormatInfo dateTimeFormat {
  1415. get { return _ci.DateTimeFormat; }
  1416. }
  1417. }
  1418. sealed class ScriptReferenceEntry
  1419. {
  1420. readonly Control _control;
  1421. readonly ScriptReference _scriptReference;
  1422. readonly bool _loadBeforeUI;
  1423. public Control Control { get { return _control; } }
  1424. public ScriptReference ScriptReference { get { return _scriptReference; } }
  1425. public bool LoadScriptsBeforeUI { get { return _loadBeforeUI; } }
  1426. public ScriptReferenceEntry (Control control, ScriptReference scriptReference, bool loadBeforeUI) {
  1427. _control = control;
  1428. _scriptReference = scriptReference;
  1429. _loadBeforeUI = loadBeforeUI;
  1430. }
  1431. }
  1432. sealed class DataItemEntry
  1433. {
  1434. readonly string _dataItem;
  1435. readonly bool _isJsonSerialized;
  1436. public string DataItem { get { return _dataItem; } }
  1437. public bool IsJsonSerialized { get { return _isJsonSerialized; } }
  1438. public DataItemEntry (string dataItem, bool isJsonSerialized) {
  1439. _dataItem = dataItem;
  1440. _isJsonSerialized = isJsonSerialized;
  1441. }
  1442. }
  1443. internal void RegisterProxy (ScriptManagerProxy scriptManagerProxy) {
  1444. if (_proxies == null)
  1445. _proxies = new List<ScriptManagerProxy> ();
  1446. _proxies.Add (scriptManagerProxy);
  1447. }
  1448. #region IScriptManager Members
  1449. void IScriptManager.RegisterOnSubmitStatementExternal (Control control, Type type, string key, string script) {
  1450. RegisterOnSubmitStatement (control, type, key, script);
  1451. }
  1452. void IScriptManager.RegisterExpandoAttributeExternal (Control control, string controlId, string attributeName, string attributeValue, bool encode) {
  1453. RegisterExpandoAttribute (control, controlId, attributeName, attributeValue, encode);
  1454. }
  1455. void IScriptManager.RegisterHiddenFieldExternal (Control control, string hiddenFieldName, string hiddenFieldInitialValue) {
  1456. RegisterHiddenField (control, hiddenFieldName, hiddenFieldInitialValue);
  1457. }
  1458. void IScriptManager.RegisterStartupScriptExternal (Control control, Type type, string key, string script, bool addScriptTags) {
  1459. RegisterStartupScript (control, type, key, script, addScriptTags);
  1460. }
  1461. void IScriptManager.RegisterArrayDeclarationExternal (Control control, string arrayName, string arrayValue) {
  1462. RegisterArrayDeclaration (control, arrayName, arrayValue);
  1463. }
  1464. void IScriptManager.RegisterClientScriptBlockExternal (Control control, Type type, string key, string script, bool addScriptTags) {
  1465. RegisterClientScriptBlock (control, type, key, script, addScriptTags);
  1466. }
  1467. void IScriptManager.RegisterClientScriptIncludeExternal (Control control, Type type, string key, string url) {
  1468. RegisterClientScriptInclude (control, type, key, url);
  1469. }
  1470. void IScriptManager.RegisterClientScriptResourceExternal (Control control, Type type, string resourceName) {
  1471. RegisterClientScriptResource (control, type, resourceName);
  1472. }
  1473. #endregion
  1474. }
  1475. }