ScriptManager.cs 59 KB

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