ScriptManager.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  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. if (serviceReference.InlineScript) {
  748. string url = control.ResolveUrl (serviceReference.Path);
  749. LogicalTypeInfo logicalTypeInfo = LogicalTypeInfo.GetLogicalTypeInfo (WebServiceParser.GetCompiledType (url, Context), url);
  750. RegisterClientScriptBlock (control, typeof (ScriptManager), url, logicalTypeInfo.Proxy, true);
  751. }
  752. else {
  753. #if TARGET_J2EE
  754. string pathInfo = "/js.invoke";
  755. #else
  756. string pathInfo = "/js";
  757. #endif
  758. string url = String.Concat (control.ResolveClientUrl (serviceReference.Path), pathInfo);
  759. RegisterClientScriptInclude (control, typeof (ScriptManager), url, url);
  760. }
  761. }
  762. public void RegisterDataItem (Control control, string dataItem) {
  763. RegisterDataItem (control, dataItem, false);
  764. }
  765. public void RegisterDataItem (Control control, string dataItem, bool isJsonSerialized) {
  766. if (!IsInAsyncPostBack)
  767. throw new InvalidOperationException ("RegisterDataItem can only be called during an async postback.");
  768. if (control == null)
  769. throw new ArgumentNullException ("control");
  770. if (_dataItems == null)
  771. _dataItems = new Dictionary<Control, DataItemEntry> ();
  772. if (_dataItems.ContainsKey (control))
  773. throw new ArgumentException (String.Format ("'{0}' already has a data item registered.", control.ID), "control");
  774. _dataItems.Add (control, new DataItemEntry (dataItem, isJsonSerialized));
  775. }
  776. public void RegisterDispose (Control control, string disposeScript) {
  777. if (control == null)
  778. throw new ArgumentNullException ("control");
  779. if (disposeScript == null)
  780. throw new ArgumentNullException ("disposeScript");
  781. UpdatePanel updatePanel = GetUpdatePanel (control);
  782. if (updatePanel == null)
  783. return;
  784. if (_disposeScripts == null)
  785. _disposeScripts = new List<RegisteredDisposeScript> ();
  786. _disposeScripts.Add (new RegisteredDisposeScript (control, disposeScript, updatePanel));
  787. }
  788. static UpdatePanel GetUpdatePanel (Control control) {
  789. if (control == null)
  790. return null;
  791. UpdatePanel parent = control.Parent as UpdatePanel;
  792. if (parent != null)
  793. return parent;
  794. return GetUpdatePanel (control.Parent);
  795. }
  796. public static void RegisterExpandoAttribute (Control control, string controlId, string attributeName, string attributeValue, bool encode) {
  797. Page page = control.Page;
  798. ScriptManager sm = GetCurrent (page);
  799. if (sm._expandoAttributes == null)
  800. sm._expandoAttributes = new List<RegisteredExpandoAttribute> ();
  801. sm._expandoAttributes.Add (new RegisteredExpandoAttribute (control, controlId, attributeName, attributeValue, encode));
  802. if (!sm.IsInAsyncPostBack)
  803. page.ClientScript.RegisterExpandoAttribute (controlId, attributeName, attributeValue, encode);
  804. }
  805. public static void RegisterHiddenField (Page page, string hiddenFieldName, string hiddenFieldInitialValue) {
  806. RegisterHiddenField ((Control) page, hiddenFieldName, hiddenFieldInitialValue);
  807. }
  808. public static void RegisterHiddenField (Control control, string hiddenFieldName, string hiddenFieldInitialValue) {
  809. Page page = control.Page;
  810. ScriptManager sm = GetCurrent (page);
  811. if (sm._hiddenFields == null)
  812. sm._hiddenFields = new List<RegisteredHiddenField> ();
  813. sm._hiddenFields.Add (new RegisteredHiddenField (control, hiddenFieldName, hiddenFieldInitialValue));
  814. if (!sm.IsInAsyncPostBack)
  815. page.ClientScript.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  816. }
  817. public static void RegisterOnSubmitStatement (Page page, Type type, string key, string script) {
  818. RegisterOnSubmitStatement ((Control) page, type, key, script);
  819. }
  820. public static void RegisterOnSubmitStatement (Control control, Type type, string key, string script) {
  821. Page page = control.Page;
  822. ScriptManager sm = GetCurrent (page);
  823. RegisterScript (ref sm._onSubmitStatements, control, type, key, script, null, false, RegisteredScriptType.OnSubmitStatement);
  824. if (!sm.IsInAsyncPostBack)
  825. page.ClientScript.RegisterOnSubmitStatement (type, key, script);
  826. }
  827. public void RegisterPostBackControl (Control control) {
  828. if (control == null)
  829. return;
  830. if (_postBackControls == null)
  831. _postBackControls = new List<Control> ();
  832. if (_postBackControls.Contains (control))
  833. return;
  834. _postBackControls.Add (control);
  835. }
  836. internal void RegisterUpdatePanel (UpdatePanel updatePanel) {
  837. if (_updatePanels == null)
  838. _updatePanels = new List<UpdatePanel> ();
  839. if (_updatePanels.Contains (updatePanel))
  840. return;
  841. _updatePanels.Add (updatePanel);
  842. }
  843. public void RegisterScriptDescriptors (IExtenderControl extenderControl) {
  844. if (extenderControl == null)
  845. return;
  846. if (_registeredExtenderControls == null || !_registeredExtenderControls.ContainsKey (extenderControl))
  847. return;
  848. Control targetControl = _registeredExtenderControls [extenderControl];
  849. RegisterScriptDescriptors ((Control) extenderControl, extenderControl.GetScriptDescriptors (targetControl));
  850. }
  851. public void RegisterScriptDescriptors (IScriptControl scriptControl) {
  852. if (scriptControl == null)
  853. return;
  854. if (_registeredScriptControls == null || !_registeredScriptControls.Contains (scriptControl))
  855. return;
  856. RegisterScriptDescriptors ((Control) scriptControl, scriptControl.GetScriptDescriptors ());
  857. }
  858. void RegisterScriptDescriptors (Control control, IEnumerable<ScriptDescriptor> scriptDescriptors) {
  859. if (scriptDescriptors == null)
  860. return;
  861. StringBuilder sb = new StringBuilder ();
  862. foreach (ScriptDescriptor scriptDescriptor in scriptDescriptors) {
  863. if (IsMultiForm) {
  864. scriptDescriptor.FormID = Page.Form.ClientID;
  865. sb.AppendLine ("Sys.Application.getInstance($get(\"" + Page.Form.ClientID + "\")).add_init(function() {");
  866. }
  867. else
  868. sb.AppendLine ("Sys.Application.add_init(function() {");
  869. sb.AppendLine (scriptDescriptor.GetScript ());
  870. sb.AppendLine ("});");
  871. }
  872. string script = sb.ToString ();
  873. RegisterStartupScript (control, typeof (ScriptDescriptor), script, script, true);
  874. }
  875. public static void RegisterStartupScript (Page page, Type type, string key, string script, bool addScriptTags) {
  876. RegisterStartupScript ((Control) page, type, key, script, addScriptTags);
  877. }
  878. public static void RegisterStartupScript (Control control, Type type, string key, string script, bool addScriptTags) {
  879. Page page = control.Page;
  880. ScriptManager sm = GetCurrent (page);
  881. RegisterScript (ref sm._startupScriptBlocks, control, type, key, script, null, addScriptTags, RegisteredScriptType.ClientStartupScript);
  882. if (!sm.IsInAsyncPostBack)
  883. page.ClientScript.RegisterStartupScript (type, key, script, addScriptTags);
  884. }
  885. public void RegisterScriptControl<TScriptControl> (TScriptControl scriptControl) where TScriptControl : Control, IScriptControl {
  886. if (scriptControl == null)
  887. throw new ArgumentNullException ("scriptControl");
  888. if (_registeredScriptControls == null)
  889. _registeredScriptControls = new List<IScriptControl> ();
  890. if (!_registeredScriptControls.Contains (scriptControl))
  891. _registeredScriptControls.Add (scriptControl);
  892. }
  893. public void RegisterExtenderControl<TExtenderControl> (TExtenderControl extenderControl, Control targetControl) where TExtenderControl : Control, IExtenderControl {
  894. if (extenderControl == null)
  895. throw new ArgumentNullException ("extenderControl");
  896. if (targetControl == null)
  897. throw new ArgumentNullException ("targetControl");
  898. if (_registeredExtenderControls == null)
  899. _registeredExtenderControls = new Dictionary<IExtenderControl, Control> ();
  900. if (!_registeredExtenderControls.ContainsKey (extenderControl))
  901. _registeredExtenderControls.Add (extenderControl, targetControl);
  902. }
  903. static void RegisterScript (ref List<RegisteredScript> scriptList, Control control, Type type, string key, string script, string url, bool addScriptTag, RegisteredScriptType scriptType) {
  904. if (scriptList == null)
  905. scriptList = new List<RegisteredScript> ();
  906. scriptList.Add (new RegisteredScript (control, type, key, script, url, addScriptTag, scriptType));
  907. }
  908. protected override void Render (HtmlTextWriter writer) {
  909. // MSDN: This method is used by control developers to extend the ScriptManager control.
  910. // Notes to Inheritors:
  911. // When overriding this method, call the base Render(HtmlTextWriter) method
  912. // so that PageRequestManager is rendered on the page.
  913. if (SupportsPartialRendering) {
  914. writer.WriteLine ("<script type=\"text/javascript\">");
  915. writer.WriteLine ("//<![CDATA[");
  916. writer.WriteLine ("Sys.WebForms.PageRequestManager._initialize('{0}', document.getElementById('{1}'));", UniqueID, Page.Form.ClientID);
  917. if (IsMultiForm)
  918. 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);
  919. else
  920. writer.WriteLine ("Sys.WebForms.PageRequestManager.getInstance()._updateControls([{0}], [{1}], [{2}], {3});", FormatUpdatePanelIDs (_updatePanels, true), FormatListIDs (_asyncPostBackControls, true), FormatListIDs (_postBackControls, true), AsyncPostBackTimeout);
  921. writer.WriteLine ("//]]");
  922. writer.WriteLine ("</script>");
  923. }
  924. base.Render (writer);
  925. }
  926. static string FormatUpdatePanelIDs (List<UpdatePanel> list, bool useSingleQuote) {
  927. if (list == null || list.Count == 0)
  928. return null;
  929. StringBuilder sb = new StringBuilder ();
  930. for (int i = 0; i < list.Count; i++) {
  931. sb.AppendFormat ("{0}{1}{2}{0},", useSingleQuote ? "'" : String.Empty, list [i].ChildrenAsTriggers ? "t" : "f", list [i].UniqueID);
  932. }
  933. if (sb.Length > 0)
  934. sb.Length--;
  935. return sb.ToString ();
  936. }
  937. static string FormatListIDs<T> (List<T> list, bool useSingleQuote) where T : Control {
  938. if (list == null || list.Count == 0)
  939. return null;
  940. StringBuilder sb = new StringBuilder ();
  941. for (int i = 0; i < list.Count; i++) {
  942. sb.AppendFormat ("{0}{1}{0},", useSingleQuote ? "'" : String.Empty, list [i].UniqueID);
  943. }
  944. if (sb.Length > 0)
  945. sb.Length--;
  946. return sb.ToString ();
  947. }
  948. public void SetFocus (Control control) {
  949. if (control == null)
  950. throw new ArgumentNullException ("control");
  951. if (IsInAsyncPostBack) {
  952. EnsureFocusClientScript ();
  953. _controlIDToFocus = control.ClientID;
  954. }
  955. else
  956. Page.SetFocus (control);
  957. }
  958. public void SetFocus (string clientID) {
  959. if (String.IsNullOrEmpty (clientID))
  960. throw new ArgumentNullException ("control");
  961. if (IsInAsyncPostBack) {
  962. EnsureFocusClientScript ();
  963. _controlIDToFocus = clientID;
  964. }
  965. else
  966. Page.SetFocus (clientID);
  967. }
  968. void EnsureFocusClientScript () {
  969. #if TARGET_DOTNET
  970. RegisterClientScriptResource (this, typeof (ClientScriptManager), "Focus.js");
  971. #endif
  972. }
  973. #region IPostBackDataHandler Members
  974. bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection) {
  975. return LoadPostData (postDataKey, postCollection);
  976. }
  977. void IPostBackDataHandler.RaisePostDataChangedEvent () {
  978. RaisePostDataChangedEvent ();
  979. }
  980. #endregion
  981. internal void WriteCallbackException (TextWriter output, Exception ex, bool writeMessage) {
  982. #if TARGET_DOTNET
  983. if (ex is HttpUnhandledException)
  984. ex = ex.InnerException;
  985. #endif
  986. HttpException httpEx = ex as HttpException;
  987. string message = AsyncPostBackErrorMessage;
  988. if (String.IsNullOrEmpty (message) && writeMessage) {
  989. HttpContext ctx = HttpContext.Current;
  990. if (IsDebuggingEnabled)
  991. message = ex.ToString ();
  992. else
  993. message = ex.Message;
  994. }
  995. WriteCallbackOutput (output, error, httpEx == null ? "500" : httpEx.GetHttpCode ().ToString (), message);
  996. }
  997. static internal void WriteCallbackRedirect (TextWriter output, string redirectUrl) {
  998. WriteCallbackOutput (output, pageRedirect, null, redirectUrl);
  999. }
  1000. void RegisterPanelForRefresh (UpdatePanel panel)
  1001. {
  1002. if (_panelsToRefresh == null)
  1003. _panelsToRefresh = new List<UpdatePanel> ();
  1004. else if (_panelsToRefresh.Contains (panel))
  1005. return;
  1006. panel.Update ();
  1007. _panelsToRefresh.Add (panel);
  1008. }
  1009. internal void WriteCallbackPanel (TextWriter output, UpdatePanel panel, StringBuilder panelOutput) {
  1010. RegisterPanelForRefresh (panel);
  1011. WriteCallbackOutput (output, updatePanel, panel.ClientID, panelOutput);
  1012. }
  1013. internal void RegisterChildUpdatePanel (UpdatePanel updatePanel) {
  1014. if (_childUpdatePanels == null)
  1015. _childUpdatePanels = new List<UpdatePanel> ();
  1016. _childUpdatePanels.Add (updatePanel);
  1017. }
  1018. static void WriteCallbackOutput (TextWriter output, string type, string name, object value) {
  1019. string str = value as string;
  1020. StringBuilder sb = value as StringBuilder;
  1021. int length = 0;
  1022. if (str != null)
  1023. length = str.Length;
  1024. else if (sb != null)
  1025. length = sb.Length;
  1026. //output.Write ("{0}|{1}|{2}|{3}|", value == null ? 0 : value.Length, type, name, value);
  1027. output.Write (length);
  1028. output.Write ('|');
  1029. output.Write (type);
  1030. output.Write ('|');
  1031. output.Write (name);
  1032. output.Write ('|');
  1033. for (int i = 0; i < length; i++)
  1034. if (str != null)
  1035. output.Write (str [i]);
  1036. else
  1037. output.Write (sb [i]);
  1038. output.Write ('|');
  1039. }
  1040. void RenderPageCallback (HtmlTextWriter output, Control container) {
  1041. Page page = (Page) container;
  1042. page.Form.SetRenderMethodDelegate (RenderFormCallback);
  1043. HtmlTextParser parser = new HtmlTextParser (output);
  1044. page.Form.RenderControl (parser);
  1045. Dictionary <string, string> pageHiddenFields = parser.HiddenFields;
  1046. if (pageHiddenFields != null)
  1047. foreach (KeyValuePair <string, string> kvp in pageHiddenFields)
  1048. WriteCallbackOutput (output, hiddenField, kvp.Key, kvp.Value);
  1049. WriteCallbackOutput (output, asyncPostBackControlIDs, null, FormatListIDs (_asyncPostBackControls, false));
  1050. WriteCallbackOutput (output, postBackControlIDs, null, FormatListIDs (_postBackControls, false));
  1051. WriteCallbackOutput (output, updatePanelIDs, null, FormatUpdatePanelIDs (_updatePanels, false));
  1052. WriteCallbackOutput (output, childUpdatePanelIDs, null, FormatListIDs (_childUpdatePanels, false));
  1053. WriteCallbackOutput (output, panelsToRefreshIDs, null, FormatListIDs (_panelsToRefresh, false));
  1054. WriteCallbackOutput (output, asyncPostBackTimeout, null, AsyncPostBackTimeout.ToString ());
  1055. if (!IsMultiForm)
  1056. WriteCallbackOutput (output, pageTitle, null, Page.Title);
  1057. if (_dataItems != null)
  1058. foreach (Control control in _dataItems.Keys) {
  1059. DataItemEntry entry = _dataItems [control];
  1060. WriteCallbackOutput (output, entry.IsJsonSerialized ? dataItemJson : dataItem, control.ClientID, entry.DataItem);
  1061. }
  1062. WriteArrayDeclarations (output);
  1063. WriteExpandoAttributes (output);
  1064. WriteScriptBlocks (output, _clientScriptBlocks);
  1065. WriteScriptBlocks (output, _startupScriptBlocks);
  1066. WriteScriptBlocks (output, _onSubmitStatements);
  1067. WriteHiddenFields (output);
  1068. if (!String.IsNullOrEmpty (_controlIDToFocus))
  1069. WriteCallbackOutput (output, focus, null, _controlIDToFocus);
  1070. if (_disposeScripts != null)
  1071. for (int i = 0; i < _disposeScripts.Count; i++) {
  1072. RegisteredDisposeScript entry = _disposeScripts [i];
  1073. if ((_panelsToRefresh != null && _panelsToRefresh.IndexOf (entry.UpdatePanel) >= 0) || (_childUpdatePanels != null && _childUpdatePanels.IndexOf (entry.UpdatePanel) >= 0))
  1074. WriteCallbackOutput (output, scriptDispose, entry.UpdatePanel.ClientID, entry.Script);
  1075. }
  1076. }
  1077. private void WriteExpandoAttributes (HtmlTextWriter writer) {
  1078. if (_expandoAttributes != null) {
  1079. for (int i = 0; i < _expandoAttributes.Count; i++) {
  1080. RegisteredExpandoAttribute attr = _expandoAttributes [i];
  1081. if (HasBeenRendered (attr.Control)) {
  1082. string value;
  1083. if (attr.Encode) {
  1084. StringWriter sw = new StringWriter ();
  1085. Newtonsoft.Json.JavaScriptUtils.WriteEscapedJavaScriptString (attr.Value, sw);
  1086. value = sw.ToString ();
  1087. }
  1088. else
  1089. value = "\"" + attr.Value + "\"";
  1090. WriteCallbackOutput (writer, expando, "document.getElementById('" + attr.ControlId + "')['" + attr.Name + "']", value);
  1091. }
  1092. }
  1093. }
  1094. }
  1095. void WriteArrayDeclarations (HtmlTextWriter writer) {
  1096. if (_arrayDeclarations != null) {
  1097. for (int i = 0; i < _arrayDeclarations.Count; i++) {
  1098. RegisteredArrayDeclaration array = _arrayDeclarations [i];
  1099. if (Page == array.Control || HasBeenRendered (array.Control))
  1100. WriteCallbackOutput (writer, arrayDeclaration, array.Name, array.Value);
  1101. }
  1102. }
  1103. }
  1104. void WriteScriptBlocks (HtmlTextWriter output, List<RegisteredScript> scriptList) {
  1105. if (scriptList == null)
  1106. return;
  1107. var registeredScripts = new Dictionary <string, RegisteredScript> ();
  1108. Control control;
  1109. for (int i = 0; i < scriptList.Count; i++) {
  1110. RegisteredScript scriptEntry = scriptList [i];
  1111. if (registeredScripts.ContainsKey (scriptEntry.Key))
  1112. continue;
  1113. control = scriptEntry.Control;
  1114. if (Page == control || HasBeenRendered (control)) {
  1115. registeredScripts.Add (scriptEntry.Key, scriptEntry);
  1116. switch (scriptEntry.ScriptType) {
  1117. case RegisteredScriptType.ClientScriptBlock:
  1118. if (scriptEntry.AddScriptTags)
  1119. WriteCallbackOutput (output, scriptBlock, scriptContentNoTags, scriptEntry.Script);
  1120. else
  1121. WriteCallbackOutput (output, scriptBlock, scriptContentWithTags, SerializeScriptBlock (scriptEntry));
  1122. break;
  1123. case RegisteredScriptType.ClientStartupScript:
  1124. if (scriptEntry.AddScriptTags)
  1125. WriteCallbackOutput (output, scriptStartupBlock, scriptContentNoTags, scriptEntry.Script);
  1126. else
  1127. WriteCallbackOutput (output, scriptStartupBlock, scriptContentWithTags, SerializeScriptBlock (scriptEntry));
  1128. break;
  1129. case RegisteredScriptType.ClientScriptInclude:
  1130. WriteCallbackOutput (output, scriptBlock, scriptPath, scriptEntry.Url);
  1131. break;
  1132. case RegisteredScriptType.OnSubmitStatement:
  1133. WriteCallbackOutput (output, onSubmit, null, scriptEntry.Script);
  1134. break;
  1135. }
  1136. }
  1137. }
  1138. }
  1139. void WriteHiddenFields (HtmlTextWriter output) {
  1140. if (_hiddenFields == null)
  1141. return;
  1142. Hashtable registeredFields = new Hashtable ();
  1143. for (int i = 0; i < _hiddenFields.Count; i++) {
  1144. RegisteredHiddenField field = _hiddenFields [i];
  1145. if (registeredFields.ContainsKey (field.Name))
  1146. continue;
  1147. if (Page == field.Control || HasBeenRendered (field.Control)) {
  1148. registeredFields.Add (field.Name, field);
  1149. WriteCallbackOutput (output, hiddenField, field.Name, field.InitialValue);
  1150. }
  1151. }
  1152. }
  1153. static string SerializeScriptBlock (RegisteredScript scriptEntry) {
  1154. try {
  1155. XmlTextReader reader = new XmlTextReader (new StringReader (scriptEntry.Script));
  1156. while (reader.Read ()) {
  1157. switch (reader.NodeType) {
  1158. case XmlNodeType.Element:
  1159. if (String.Compare ("script", reader.Name, StringComparison.OrdinalIgnoreCase) == 0) {
  1160. Dictionary<string, string> dic = new Dictionary<string, string> ();
  1161. while (reader.MoveToNextAttribute ()) {
  1162. dic.Add (reader.Name, reader.Value);
  1163. }
  1164. reader.MoveToContent ();
  1165. dic.Add ("text", reader.ReadInnerXml ());
  1166. return JavaScriptSerializer.DefaultSerializer.Serialize (dic);
  1167. }
  1168. break;
  1169. default:
  1170. continue;
  1171. }
  1172. }
  1173. }
  1174. catch {
  1175. }
  1176. 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));
  1177. }
  1178. void RenderFormCallback (HtmlTextWriter output, Control container) {
  1179. output = ((HtmlTextParser) output).ResponseOutput;
  1180. HtmlForm form = (HtmlForm) container;
  1181. HtmlTextWriter writer = new HtmlDropWriter (output);
  1182. if (form.HasControls ()) {
  1183. for (int i = 0; i < form.Controls.Count; i++) {
  1184. form.Controls [i].RenderControl (writer);
  1185. }
  1186. }
  1187. }
  1188. internal class AlternativeHtmlTextWriter : HtmlTextWriter
  1189. {
  1190. readonly HtmlTextWriter _responseOutput;
  1191. public HtmlTextWriter ResponseOutput {
  1192. get { return _responseOutput; }
  1193. }
  1194. public AlternativeHtmlTextWriter (TextWriter writer, HtmlTextWriter responseOutput)
  1195. : base (writer) {
  1196. _responseOutput = responseOutput;
  1197. }
  1198. }
  1199. sealed class HtmlTextParser : AlternativeHtmlTextWriter
  1200. {
  1201. bool _done;
  1202. public Dictionary <string, string> _hiddenFields;
  1203. public Dictionary <string, string> HiddenFields {
  1204. get { return _hiddenFields; }
  1205. }
  1206. public HtmlTextParser (HtmlTextWriter responseOutput)
  1207. : this (new TextParser (responseOutput), responseOutput) {
  1208. }
  1209. HtmlTextParser (TextParser parser, HtmlTextWriter responseOutput)
  1210. : base (parser, responseOutput)
  1211. {
  1212. parser.HiddenFieldParsed += new TextParser.TextParserHiddenFieldParsedEventHandler (OnHiddenFieldParsed);
  1213. }
  1214. void OnHiddenFieldParsed (TextParser sender, TextParserHiddenFieldParsedEventArgs args)
  1215. {
  1216. if (_hiddenFields == null)
  1217. _hiddenFields = new Dictionary <string, string> ();
  1218. _hiddenFields [args.Name] = args.Value;
  1219. }
  1220. public override void WriteAttribute (string name, string value) {
  1221. if (!_done && String.Compare ("action", name, StringComparison.OrdinalIgnoreCase) == 0) {
  1222. _done = true;
  1223. ScriptManager.WriteCallbackOutput (ResponseOutput, formAction, null, value);
  1224. return;
  1225. }
  1226. base.WriteAttribute (name, value);
  1227. }
  1228. }
  1229. sealed class TextParserHiddenFieldParsedEventArgs : EventArgs
  1230. {
  1231. public string Name {
  1232. get;
  1233. private set;
  1234. }
  1235. public string Value {
  1236. get;
  1237. private set;
  1238. }
  1239. public TextParserHiddenFieldParsedEventArgs (string name, string value)
  1240. {
  1241. this.Name = name;
  1242. this.Value = value;
  1243. }
  1244. }
  1245. sealed class TextParser : TextWriter
  1246. {
  1247. public delegate void TextParserHiddenFieldParsedEventHandler (TextParser sender, TextParserHiddenFieldParsedEventArgs args);
  1248. static object textParserHiddenFieldParsedEvent = new object ();
  1249. int _state;
  1250. char _charState = (char) 255;
  1251. const char nullCharState = (char) 255;
  1252. StringBuilder _sb = new StringBuilder ();
  1253. Dictionary<string, string> _currentField;
  1254. string _currentAttribute;
  1255. readonly HtmlTextWriter _responseOutput;
  1256. TextParserHiddenFieldParsedEventHandler _hiddenFieldParsedHandler;
  1257. public event TextParserHiddenFieldParsedEventHandler HiddenFieldParsed {
  1258. add { _hiddenFieldParsedHandler = value; }
  1259. remove { _hiddenFieldParsedHandler = null; }
  1260. }
  1261. public override Encoding Encoding {
  1262. get { return Encoding.UTF8; }
  1263. }
  1264. public TextParser (HtmlTextWriter responseOutput) {
  1265. _responseOutput = responseOutput;
  1266. }
  1267. public override void Write (char value) {
  1268. switch (_state) {
  1269. case 0:
  1270. ParseBeginTag (value);
  1271. break;
  1272. case 1:
  1273. ParseAttributeName (value);
  1274. break;
  1275. case 2:
  1276. ParseAttributeValue (value);
  1277. break;
  1278. }
  1279. }
  1280. private void ParseAttributeValue (char value) {
  1281. switch (value) {
  1282. case '>':
  1283. ResetState ();
  1284. break;
  1285. case '"':
  1286. _currentField.Add (_currentAttribute, _sb.ToString ());
  1287. _state = 1;
  1288. _sb.Length = 0;
  1289. ProbeWriteOutput ();
  1290. break;
  1291. default:
  1292. _sb.Append (value);
  1293. break;
  1294. }
  1295. }
  1296. private void ParseAttributeName (char value) {
  1297. switch (value) {
  1298. case '>':
  1299. ResetState ();
  1300. break;
  1301. case ' ':
  1302. case '=':
  1303. break;
  1304. case '"':
  1305. _currentAttribute = _sb.ToString ();
  1306. _state = 2;
  1307. _sb.Length = 0;
  1308. break;
  1309. default:
  1310. _sb.Append (value);
  1311. break;
  1312. }
  1313. }
  1314. void ParseBeginTag (char value) {
  1315. switch (_charState) {
  1316. case nullCharState:
  1317. if (value == '<')
  1318. _charState = value;
  1319. break;
  1320. case '<':
  1321. if (value == 'i')
  1322. _charState = value;
  1323. else
  1324. ResetState ();
  1325. break;
  1326. case 'i':
  1327. if (value == 'n')
  1328. _charState = value;
  1329. else
  1330. ResetState ();
  1331. break;
  1332. case 'n':
  1333. if (value == 'p')
  1334. _charState = value;
  1335. else
  1336. ResetState ();
  1337. break;
  1338. case 'p':
  1339. if (value == 'u')
  1340. _charState = value;
  1341. else
  1342. ResetState ();
  1343. break;
  1344. case 'u':
  1345. if (value == 't')
  1346. _charState = value;
  1347. else
  1348. ResetState ();
  1349. break;
  1350. case 't':
  1351. if (value == ' ') {
  1352. _state = 1;
  1353. _currentField = new Dictionary<string, string> ();
  1354. }
  1355. else
  1356. ResetState ();
  1357. break;
  1358. }
  1359. }
  1360. private void ResetState () {
  1361. _charState = nullCharState;
  1362. _state = 0;
  1363. _sb.Length = 0;
  1364. }
  1365. private void ProbeWriteOutput () {
  1366. if (!_currentField.ContainsKey ("name"))
  1367. return;
  1368. if (!_currentField.ContainsKey ("value"))
  1369. return;
  1370. string value = _currentField ["value"];
  1371. if (value == null)
  1372. return;
  1373. if (_hiddenFieldParsedHandler != null)
  1374. _hiddenFieldParsedHandler (this, new TextParserHiddenFieldParsedEventArgs (_currentField ["name"], HttpUtility.HtmlDecode (value)));
  1375. else
  1376. ScriptManager.WriteCallbackOutput (_responseOutput, hiddenField, _currentField ["name"], HttpUtility.HtmlDecode (value));
  1377. }
  1378. }
  1379. sealed class HtmlDropWriter : AlternativeHtmlTextWriter
  1380. {
  1381. public HtmlDropWriter (HtmlTextWriter responseOutput)
  1382. : base (new DropWriter (), responseOutput) {
  1383. }
  1384. }
  1385. sealed class DropWriter : TextWriter
  1386. {
  1387. public override Encoding Encoding {
  1388. get { return Encoding.UTF8; }
  1389. }
  1390. }
  1391. sealed class CultureInfoSerializer
  1392. {
  1393. readonly CultureInfo _ci;
  1394. public CultureInfoSerializer (CultureInfo ci) {
  1395. if (ci == null)
  1396. throw new ArgumentNullException ("ci");
  1397. _ci = ci;
  1398. }
  1399. public string name {
  1400. get { return _ci.Name; }
  1401. }
  1402. public NumberFormatInfo numberFormat {
  1403. get { return _ci.NumberFormat; }
  1404. }
  1405. public DateTimeFormatInfo dateTimeFormat {
  1406. get { return _ci.DateTimeFormat; }
  1407. }
  1408. }
  1409. sealed class ScriptReferenceEntry
  1410. {
  1411. readonly Control _control;
  1412. readonly ScriptReference _scriptReference;
  1413. readonly bool _loadBeforeUI;
  1414. public Control Control { get { return _control; } }
  1415. public ScriptReference ScriptReference { get { return _scriptReference; } }
  1416. public bool LoadScriptsBeforeUI { get { return _loadBeforeUI; } }
  1417. public ScriptReferenceEntry (Control control, ScriptReference scriptReference, bool loadBeforeUI) {
  1418. _control = control;
  1419. _scriptReference = scriptReference;
  1420. _loadBeforeUI = loadBeforeUI;
  1421. }
  1422. }
  1423. sealed class DataItemEntry
  1424. {
  1425. readonly string _dataItem;
  1426. readonly bool _isJsonSerialized;
  1427. public string DataItem { get { return _dataItem; } }
  1428. public bool IsJsonSerialized { get { return _isJsonSerialized; } }
  1429. public DataItemEntry (string dataItem, bool isJsonSerialized) {
  1430. _dataItem = dataItem;
  1431. _isJsonSerialized = isJsonSerialized;
  1432. }
  1433. }
  1434. internal void RegisterProxy (ScriptManagerProxy scriptManagerProxy) {
  1435. if (_proxies == null)
  1436. _proxies = new List<ScriptManagerProxy> ();
  1437. _proxies.Add (scriptManagerProxy);
  1438. }
  1439. #region IScriptManager Members
  1440. void IScriptManager.RegisterOnSubmitStatementExternal (Control control, Type type, string key, string script) {
  1441. RegisterOnSubmitStatement (control, type, key, script);
  1442. }
  1443. void IScriptManager.RegisterExpandoAttributeExternal (Control control, string controlId, string attributeName, string attributeValue, bool encode) {
  1444. RegisterExpandoAttribute (control, controlId, attributeName, attributeValue, encode);
  1445. }
  1446. void IScriptManager.RegisterHiddenFieldExternal (Control control, string hiddenFieldName, string hiddenFieldInitialValue) {
  1447. RegisterHiddenField (control, hiddenFieldName, hiddenFieldInitialValue);
  1448. }
  1449. void IScriptManager.RegisterStartupScriptExternal (Control control, Type type, string key, string script, bool addScriptTags) {
  1450. RegisterStartupScript (control, type, key, script, addScriptTags);
  1451. }
  1452. void IScriptManager.RegisterArrayDeclarationExternal (Control control, string arrayName, string arrayValue) {
  1453. RegisterArrayDeclaration (control, arrayName, arrayValue);
  1454. }
  1455. void IScriptManager.RegisterClientScriptBlockExternal (Control control, Type type, string key, string script, bool addScriptTags) {
  1456. RegisterClientScriptBlock (control, type, key, script, addScriptTags);
  1457. }
  1458. void IScriptManager.RegisterClientScriptIncludeExternal (Control control, Type type, string key, string url) {
  1459. RegisterClientScriptInclude (control, type, key, url);
  1460. }
  1461. void IScriptManager.RegisterClientScriptResourceExternal (Control control, Type type, string resourceName) {
  1462. RegisterClientScriptResource (control, type, resourceName);
  1463. }
  1464. #endregion
  1465. }
  1466. }