1 //------------------------------------------------------------------------------ 2 // <copyright file="ScriptManager.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 //------------------------------------------------------------------------------ 6 7 namespace System.Web.UI { 8 using System; 9 using System.Collections; 10 using System.Collections.Generic; 11 using System.Collections.ObjectModel; 12 using System.Collections.Specialized; 13 using System.ComponentModel; 14 using System.Configuration; 15 using System.Diagnostics.CodeAnalysis; 16 using System.Drawing; 17 using System.Drawing.Design; 18 using System.Globalization; 19 using System.Linq; 20 using System.Reflection; 21 using System.Security; 22 using System.Security.Permissions; 23 using System.Text; 24 using System.Web; 25 using System.Web.Compilation; 26 using System.Web.Configuration; 27 using System.Web.Globalization; 28 using System.Web.Handlers; 29 using System.Web.Hosting; 30 using System.Web.Resources; 31 using System.Web.Script; 32 using System.Web.Script.Serialization; 33 using System.Web.Script.Services; 34 using System.Web.Security.Cryptography; 35 using System.Web.UI.Design; 36 using System.Web.Util; 37 38 [ 39 DefaultProperty("Scripts"), 40 Designer("System.Web.UI.Design.ScriptManagerDesigner, " + AssemblyRef.SystemWebExtensionsDesign), 41 NonVisualControl(), 42 ParseChildren(true), 43 PersistChildren(false), 44 ToolboxBitmap(typeof(EmbeddedResourceFinder), "System.Web.Resources.ScriptManager.bmp") 45 ] 46 public class ScriptManager : Control, IPostBackDataHandler, IPostBackEventHandler, IControl, IScriptManager, IScriptManagerInternal { 47 private readonly new IPage _page; 48 private readonly IControl _control; 49 private readonly ICompilationSection _appLevelCompilationSection; 50 private readonly IDeploymentSection _deploymentSection; 51 private readonly ICustomErrorsSection _customErrorsSection; 52 private static bool _ajaxFrameworkAssemblyConfigChecked; 53 private static Assembly _defaultAjaxFrameworkAssembly = null; 54 private Assembly _ajaxFrameworkAssembly = DefaultAjaxFrameworkAssembly; 55 56 private const int AsyncPostBackTimeoutDefault = 90; 57 58 private ScriptMode _scriptMode; 59 private string _scriptPath; 60 private CompositeScriptReference _compositeScript; 61 private ScriptReferenceCollection _scripts; 62 private ServiceReferenceCollection _services; 63 private bool? _isRestMethodCall; 64 private bool? _isSecureConnection; 65 private List<ScriptManagerProxy> _proxies; 66 private AjaxFrameworkMode _ajaxFrameworkMode = AjaxFrameworkMode.Enabled; 67 private bool _enablePartialRendering = true; 68 private bool _supportsPartialRendering = true; 69 internal bool _supportsPartialRenderingSetByUser; 70 internal ScriptReferenceBase _applicationServicesReference; 71 private string _appServicesInitializationScript; 72 private bool _enableScriptGlobalization; 73 private bool _enableScriptLocalization = true; 74 private bool _enablePageMethods; 75 private bool _loadScriptsBeforeUI = true; 76 private bool _initCompleted; 77 private bool _preRenderCompleted; 78 private bool _isInAsyncPostBack; 79 private int _asyncPostBackTimeout = AsyncPostBackTimeoutDefault; 80 private bool _allowCustomErrorsRedirect = true; 81 private string _asyncPostBackErrorMessage; 82 private bool _zip; 83 private bool _zipSet; 84 private int _uniqueScriptCounter; 85 private bool _enableCdn; 86 private bool _enableCdnFallback = true; 87 private HashSet<String> _scriptPathsDefiningSys = new HashSet<String>(StringComparer.OrdinalIgnoreCase); 88 89 private static readonly object AsyncPostBackErrorEvent = new object(); 90 private static readonly object ResolveCompositeScriptReferenceEvent = new object(); 91 private static readonly object ResolveScriptReferenceEvent = new object(); 92 private static HashSet<String> _splitFrameworkScript; 93 private ScriptRegistrationManager _scriptRegistration; 94 private PageRequestManager _pageRequestManager; 95 96 private ScriptControlManager _scriptControlManager; 97 98 private ProfileServiceManager _profileServiceManager; 99 private AuthenticationServiceManager _authenticationServiceManager; 100 private RoleServiceManager _roleServiceManager; 101 102 private BundleReflectionHelper _bundleReflectionHelper; 103 104 // History fields 105 private bool _enableSecureHistoryState = true; 106 private bool _enableHistory; 107 private bool _isNavigating; 108 private string _clientNavigateHandler; 109 // Using a hashtable here, which will be more efficiently serialized 110 // by the page state formatter than a Dictionary<string, object> 111 // or een NameValueCollection. 112 private Hashtable _initialState; 113 private static readonly object NavigateEvent = new object(); 114 private bool _newPointCreated; 115 ScriptManager()116 static ScriptManager() { 117 ClientScriptManager._scriptResourceMapping = new ScriptResourceMapping(); 118 } 119 ScriptManager()120 public ScriptManager() { 121 } 122 ScriptManager(IControl control, IPage page, ICompilationSection appLevelCompilationSection, IDeploymentSection deploymentSection, ICustomErrorsSection customErrorsSection, Assembly ajaxFrameworkAssembly, bool isSecureConnection)123 internal ScriptManager(IControl control, 124 IPage page, 125 ICompilationSection appLevelCompilationSection, 126 IDeploymentSection deploymentSection, 127 ICustomErrorsSection customErrorsSection, 128 Assembly ajaxFrameworkAssembly, 129 bool isSecureConnection) { 130 _control = control; 131 _page = page; 132 _appLevelCompilationSection = appLevelCompilationSection; 133 _deploymentSection = deploymentSection; 134 _customErrorsSection = customErrorsSection; 135 _ajaxFrameworkAssembly = ajaxFrameworkAssembly ?? DefaultAjaxFrameworkAssembly; 136 _isSecureConnection = isSecureConnection; 137 } 138 139 [ 140 ResourceDescription("ScriptManager_AjaxFrameworkAssembly"), 141 Browsable(false) 142 ] 143 public virtual Assembly AjaxFrameworkAssembly { 144 get { 145 // value is set to the static DefaultAjaxFrameworkAssembly one at constructor time, 146 // so this property value can't change in the middle of a request. 147 return _ajaxFrameworkAssembly; 148 } 149 } 150 151 [ 152 DefaultValue(true), 153 ResourceDescription("ScriptManager_AllowCustomErrorsRedirect"), 154 Category("Behavior"), 155 ] 156 public bool AllowCustomErrorsRedirect { 157 get { 158 return _allowCustomErrorsRedirect; 159 } 160 set { 161 _allowCustomErrorsRedirect = value; 162 } 163 } 164 165 private ICompilationSection AppLevelCompilationSection { 166 get { 167 if (_appLevelCompilationSection != null) { 168 return _appLevelCompilationSection; 169 } 170 else { 171 return AppLevelCompilationSectionCache.Instance; 172 } 173 } 174 } 175 176 [ 177 DefaultValue(""), 178 ResourceDescription("ScriptManager_AsyncPostBackErrorMessage"), 179 Category("Behavior") 180 ] 181 public string AsyncPostBackErrorMessage { 182 get { 183 if (_asyncPostBackErrorMessage == null) { 184 return String.Empty; 185 } 186 return _asyncPostBackErrorMessage; 187 } 188 set { 189 _asyncPostBackErrorMessage = value; 190 } 191 } 192 193 // FxCop does not flag this as a violation, because it is an implicit implementation of 194 // IScriptManagerInternal.AsyncPostBackSourceElementID. 195 // 196 [ 197 Browsable(false), 198 SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase") 199 ] 200 public string AsyncPostBackSourceElementID { 201 get { 202 return PageRequestManager.AsyncPostBackSourceElementID; 203 } 204 } 205 206 [ 207 ResourceDescription("ScriptManager_AsyncPostBackTimeout"), 208 Category("Behavior"), 209 DefaultValue(AsyncPostBackTimeoutDefault) 210 ] 211 public int AsyncPostBackTimeout { 212 get { 213 return _asyncPostBackTimeout; 214 } 215 set { 216 if (value < 0) { 217 throw new ArgumentOutOfRangeException("value"); 218 } 219 _asyncPostBackTimeout = value; 220 } 221 } 222 223 [ 224 ResourceDescription("ScriptManager_AuthenticationService"), 225 Category("Behavior"), 226 DefaultValue(null), 227 DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 228 PersistenceMode(PersistenceMode.InnerProperty), 229 MergableProperty(false), 230 ] 231 public AuthenticationServiceManager AuthenticationService { 232 get { 233 if (_authenticationServiceManager == null) { 234 _authenticationServiceManager = new AuthenticationServiceManager(); 235 } 236 return _authenticationServiceManager; 237 } 238 } 239 240 internal BundleReflectionHelper BundleReflectionHelper { 241 get { 242 if (_bundleReflectionHelper == null) { 243 _bundleReflectionHelper = new BundleReflectionHelper(); 244 } 245 return _bundleReflectionHelper; 246 } 247 set { 248 _bundleReflectionHelper = value; 249 } 250 } 251 252 public static ScriptResourceMapping ScriptResourceMapping { 253 get { 254 return (ScriptResourceMapping)ClientScriptManager._scriptResourceMapping; 255 } 256 } 257 258 [ 259 ResourceDescription("ScriptManager_ClientNavigateHandler"), 260 Category("Behavior"), 261 DefaultValue("") 262 ] 263 public string ClientNavigateHandler { 264 get { 265 return _clientNavigateHandler ?? String.Empty; 266 } 267 set { 268 _clientNavigateHandler = value; 269 } 270 } 271 272 [ 273 ResourceDescription("ScriptManager_CompositeScript"), 274 Category("Behavior"), 275 DefaultValue(null), 276 DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 277 PersistenceMode(PersistenceMode.InnerProperty), 278 MergableProperty(false), 279 ] 280 public CompositeScriptReference CompositeScript { 281 get { 282 if (_compositeScript == null) { 283 _compositeScript = new CompositeScriptReference(); 284 } 285 return _compositeScript; 286 } 287 } 288 289 internal IControl Control { 290 get { 291 if (_control != null) { 292 return _control; 293 } 294 else { 295 return this; 296 } 297 } 298 } 299 300 internal ICustomErrorsSection CustomErrorsSection { 301 [SecurityCritical()] 302 get { 303 if (_customErrorsSection != null) { 304 return _customErrorsSection; 305 } 306 else { 307 return GetCustomErrorsSectionWithAssert(); 308 } 309 } 310 } 311 312 internal static Assembly DefaultAjaxFrameworkAssembly { 313 get { 314 if ((_defaultAjaxFrameworkAssembly == null) && !_ajaxFrameworkAssemblyConfigChecked && AssemblyCache._useCompilationSection) { 315 IEnumerable<Assembly> referencedAssemblies; 316 // In a hosted environment we want to get the assemblies from the BuildManager. This will include 317 // dynamically added assemblies through the PreAppStart phase. 318 // In non-hosted scenarios (VS designer) we want to look the assemblies directly from the config system 319 // since the PreAppStart phase will not execute. 320 if (HostingEnvironment.IsHosted) { 321 referencedAssemblies = BuildManager.GetReferencedAssemblies().OfType<Assembly>(); 322 } 323 else { 324 CompilationSection compilationSection = RuntimeConfig.GetAppConfig().Compilation; 325 referencedAssemblies = compilationSection.Assemblies.OfType<AssemblyInfo>().SelectMany(assemblyInfo => assemblyInfo.AssemblyInternal); 326 } 327 328 foreach (Assembly assembly in referencedAssemblies) { 329 if (assembly != AssemblyCache.SystemWebExtensions) { 330 AjaxFrameworkAssemblyAttribute attribute = 331 AssemblyCache.GetAjaxFrameworkAssemblyAttribute(assembly); 332 if (attribute != null) { 333 _defaultAjaxFrameworkAssembly = attribute.GetDefaultAjaxFrameworkAssembly(assembly); 334 break; 335 } 336 } 337 _ajaxFrameworkAssemblyConfigChecked = true; 338 } 339 _ajaxFrameworkAssemblyConfigChecked = true; 340 } 341 return _defaultAjaxFrameworkAssembly ?? AssemblyCache.SystemWebExtensions; 342 } 343 set { 344 if (value == null) { 345 throw new ArgumentNullException("value"); 346 } 347 _defaultAjaxFrameworkAssembly = value; 348 } 349 } 350 351 private IDeploymentSection DeploymentSection { 352 get { 353 if (_deploymentSection != null) { 354 return _deploymentSection; 355 } 356 else { 357 return DeploymentSectionCache.Instance; 358 } 359 } 360 } 361 362 internal bool DeploymentSectionRetail { 363 get { 364 return DeploymentSection.Retail; 365 } 366 } 367 368 [ 369 ResourceDescription("ScriptManager_EmptyPageUrl"), 370 Category("Appearance"), 371 Editor(typeof(UrlEditor), typeof(UITypeEditor)), 372 DefaultValue(""), 373 UrlProperty, 374 SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "Consistent with other asp.net url properties.") 375 ] 376 public virtual string EmptyPageUrl { 377 get { 378 return ViewState["EmptyPageUrl"] as string ?? string.Empty; 379 } 380 set { 381 ViewState["EmptyPageUrl"] = value; 382 } 383 } 384 385 [ 386 ResourceDescription("ScriptManager_EnableCdn"), 387 Category("Behavior"), 388 DefaultValue(false), 389 ] 390 public bool EnableCdn { 391 get { 392 return _enableCdn; 393 } 394 set { 395 if (_preRenderCompleted) { 396 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotChangeEnableCdn); 397 } 398 _enableCdn = value; 399 } 400 } 401 402 [ 403 ResourceDescription("ScriptManager_EnableCdnFallback"), 404 Category("Behavior"), 405 DefaultValue(true) 406 ] 407 public bool EnableCdnFallback { 408 get { 409 return _enableCdnFallback; 410 } 411 set { 412 if (_preRenderCompleted) { 413 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotChangeEnableCdnFallback); 414 } 415 _enableCdnFallback = value; 416 } 417 } 418 419 [ 420 ResourceDescription("ScriptManager_EnableHistory"), 421 Category("Behavior"), 422 DefaultValue(false), 423 ] 424 public bool EnableHistory { 425 get { 426 return _enableHistory; 427 } 428 set { 429 if (_initCompleted) { 430 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotChangeEnableHistory); 431 } 432 _enableHistory = value; 433 } 434 } 435 436 [ 437 ResourceDescription("ScriptManager_AjaxFrameworkMode"), 438 Category("Behavior"), 439 DefaultValue(AjaxFrameworkMode.Enabled), 440 ] 441 public AjaxFrameworkMode AjaxFrameworkMode { 442 get { 443 return _ajaxFrameworkMode; 444 } 445 set { 446 if (value < AjaxFrameworkMode.Enabled || value > AjaxFrameworkMode.Explicit) { 447 throw new ArgumentOutOfRangeException("value"); 448 } 449 if (_initCompleted) { 450 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotChangeAjaxFrameworkMode); 451 } 452 _ajaxFrameworkMode = value; 453 } 454 } 455 456 [ 457 ResourceDescription("ScriptManager_EnablePageMethods"), 458 Category("Behavior"), 459 DefaultValue(false), 460 ] 461 public bool EnablePageMethods { 462 get { 463 return _enablePageMethods; 464 } 465 set { 466 _enablePageMethods = value; 467 } 468 } 469 470 [ 471 ResourceDescription("ScriptManager_EnablePartialRendering"), 472 Category("Behavior"), 473 DefaultValue(true), 474 ] 475 public bool EnablePartialRendering { 476 get { 477 return _enablePartialRendering; 478 } 479 set { 480 if (_initCompleted) { 481 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotChangeEnablePartialRendering); 482 } 483 _enablePartialRendering = value; 484 } 485 } 486 487 [ 488 ResourceDescription("ScriptManager_EnableScriptGlobalization"), 489 Category("Behavior"), 490 DefaultValue(false), 491 ] 492 public bool EnableScriptGlobalization { 493 get { 494 return _enableScriptGlobalization; 495 } 496 set { 497 if (_initCompleted) { 498 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotChangeEnableScriptGlobalization); 499 } 500 _enableScriptGlobalization = value; 501 } 502 } 503 504 [ 505 ResourceDescription("ScriptManager_EnableScriptLocalization"), 506 Category("Behavior"), 507 DefaultValue(true), 508 ] 509 public bool EnableScriptLocalization { 510 get { 511 return _enableScriptLocalization; 512 } 513 set { 514 _enableScriptLocalization = value; 515 } 516 } 517 518 [ 519 ResourceDescription("ScriptManager_EnableSecureHistoryState"), 520 Category("Behavior"), 521 DefaultValue(true), 522 ] 523 public bool EnableSecureHistoryState { 524 get { 525 return _enableSecureHistoryState; 526 } 527 set { 528 _enableSecureHistoryState = value; 529 } 530 } 531 532 internal bool HasAuthenticationServiceManager { 533 get { 534 return this._authenticationServiceManager != null; 535 } 536 } 537 538 internal bool HasProfileServiceManager { 539 get { 540 return this._profileServiceManager != null; 541 } 542 } 543 544 internal bool HasRoleServiceManager { 545 get { 546 return this._roleServiceManager != null; 547 } 548 } 549 550 [Browsable(false)] 551 public bool IsDebuggingEnabled { 552 get { 553 // Returns false when: 554 // - Deployment mode is set to retail (override all other settings) 555 // - ScriptMode is set to Auto or Inherit, and debugging it not enabled in web.config 556 // - ScriptMode is set to Release 557 558 if (DeploymentSectionRetail) { 559 return false; 560 } 561 if (ScriptMode == ScriptMode.Auto || ScriptMode == ScriptMode.Inherit) { 562 return AppLevelCompilationSection.Debug; 563 } 564 return (ScriptMode == ScriptMode.Debug); 565 } 566 } 567 568 [ 569 Browsable(false), 570 SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase") 571 ] 572 public bool IsInAsyncPostBack { 573 get { 574 return _isInAsyncPostBack; 575 } 576 } 577 578 [ 579 Browsable(false), 580 SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase") 581 ] 582 public bool IsNavigating { 583 get { 584 return _isNavigating; 585 } 586 } 587 588 internal bool IsRestMethodCall { 589 get { 590 if (!_isRestMethodCall.HasValue) { 591 _isRestMethodCall = (Context != null) && RestHandlerFactory.IsRestMethodCall(Context.Request); 592 } 593 return _isRestMethodCall.Value; 594 } 595 } 596 597 internal bool IsSecureConnection { 598 get { 599 if (!_isSecureConnection.HasValue) { 600 _isSecureConnection = (Context != null) && (Context.Request != null) && Context.Request.IsSecureConnection; 601 } 602 return _isSecureConnection.Value; 603 } 604 } 605 606 internal IPage IPage { 607 get { 608 if (_page != null) { 609 return _page; 610 } 611 else { 612 Page page = Page; 613 if (page == null) { 614 throw new InvalidOperationException(AtlasWeb.Common_PageCannotBeNull); 615 } 616 return new PageWrapper(page); 617 } 618 } 619 } 620 621 // DevDiv bugs #46710: Ability to specify whether scripts are loaded inline at the top of the form (before UI), or via ScriptLoader (after UI). 622 [ 623 ResourceDescription("ScriptManager_LoadScriptsBeforeUI"), 624 Category("Behavior"), 625 DefaultValue(true), 626 ] 627 public bool LoadScriptsBeforeUI { 628 get { 629 return _loadScriptsBeforeUI; 630 } 631 set { 632 _loadScriptsBeforeUI = value; 633 } 634 } 635 636 private PageRequestManager PageRequestManager { 637 get { 638 if (_pageRequestManager == null) { 639 _pageRequestManager = new PageRequestManager(this); 640 } 641 return _pageRequestManager; 642 } 643 } 644 645 [ 646 ResourceDescription("ScriptManager_ProfileService"), 647 Category("Behavior"), 648 DefaultValue(null), 649 DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 650 PersistenceMode(PersistenceMode.InnerProperty), 651 MergableProperty(false), 652 ] 653 public ProfileServiceManager ProfileService { 654 get { 655 if (_profileServiceManager == null) { 656 _profileServiceManager = new ProfileServiceManager(); 657 } 658 return _profileServiceManager; 659 } 660 } 661 662 internal List<ScriptManagerProxy> Proxies { 663 get { 664 if (_proxies == null) { 665 _proxies = new List<ScriptManagerProxy>(); 666 } 667 return _proxies; 668 } 669 } 670 671 [ 672 ResourceDescription("ScriptManager_RoleService"), 673 Category("Behavior"), 674 DefaultValue(null), 675 DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 676 PersistenceMode(PersistenceMode.InnerProperty), 677 MergableProperty(false), 678 ] 679 public RoleServiceManager RoleService { 680 get { 681 if (_roleServiceManager == null) { 682 _roleServiceManager = new RoleServiceManager(); 683 } 684 return _roleServiceManager; 685 } 686 } 687 688 internal ScriptControlManager ScriptControlManager { 689 get { 690 if (_scriptControlManager == null) { 691 _scriptControlManager = new ScriptControlManager(this); 692 } 693 return _scriptControlManager; 694 } 695 } 696 697 [ 698 ResourceDescription("ScriptManager_ScriptMode"), 699 Category("Behavior"), 700 DefaultValue(ScriptMode.Auto), 701 ] 702 public ScriptMode ScriptMode { 703 get { 704 return _scriptMode; 705 } 706 set { 707 if (value < ScriptMode.Auto || value > ScriptMode.Release) { 708 throw new ArgumentOutOfRangeException("value"); 709 } 710 _scriptMode = value; 711 } 712 } 713 714 internal ScriptRegistrationManager ScriptRegistration { 715 get { 716 if (_scriptRegistration == null) { 717 _scriptRegistration = new ScriptRegistrationManager(this); 718 } 719 return _scriptRegistration; 720 } 721 } 722 723 [ 724 ResourceDescription("ScriptManager_Scripts"), 725 Category("Behavior"), 726 Editor("System.Web.UI.Design.CollectionEditorBase, " + 727 AssemblyRef.SystemWebExtensionsDesign, typeof(UITypeEditor)), 728 DefaultValue(null), 729 PersistenceMode(PersistenceMode.InnerProperty), 730 MergableProperty(false), 731 ] 732 public ScriptReferenceCollection Scripts { 733 get { 734 if (_scripts == null) { 735 _scripts = new ScriptReferenceCollection(); 736 } 737 return _scripts; 738 } 739 } 740 741 [ 742 ResourceDescription("ScriptManager_ScriptPath"), 743 Category("Behavior"), 744 DefaultValue(""), 745 Obsolete("This property is obsolete. Set the Path property on each individual ScriptReference instead."), 746 ] 747 public string ScriptPath { 748 get { 749 return (_scriptPath == null) ? String.Empty : _scriptPath; 750 } 751 set { 752 _scriptPath = value; 753 } 754 } 755 756 [ 757 ResourceDescription("ScriptManager_Services"), 758 Category("Behavior"), 759 Editor("System.Web.UI.Design.ServiceReferenceCollectionEditor, " + 760 AssemblyRef.SystemWebExtensionsDesign, typeof(UITypeEditor)), 761 DefaultValue(null), 762 PersistenceMode(PersistenceMode.InnerProperty), 763 MergableProperty(false), 764 ] 765 public ServiceReferenceCollection Services { 766 get { 767 if (_services == null) { 768 _services = new ServiceReferenceCollection(); 769 } 770 return _services; 771 } 772 } 773 774 private static HashSet<String> SplitFrameworkScripts { 775 get { 776 if (_splitFrameworkScript == null) { 777 HashSet<String> scripts = new HashSet<String>(); 778 scripts.Add("MicrosoftAjaxComponentModel.js"); 779 scripts.Add("MicrosoftAjaxComponentModel.debug.js"); 780 scripts.Add("MicrosoftAjaxCore.js"); 781 scripts.Add("MicrosoftAjaxCore.debug.js"); 782 scripts.Add("MicrosoftAjaxGlobalization.js"); 783 scripts.Add("MicrosoftAjaxGlobalization.debug.js"); 784 scripts.Add("MicrosoftAjaxHistory.js"); 785 scripts.Add("MicrosoftAjaxHistory.debug.js"); 786 scripts.Add("MicrosoftAjaxNetwork.js"); 787 scripts.Add("MicrosoftAjaxNetwork.debug.js"); 788 scripts.Add("MicrosoftAjaxSerialization.js"); 789 scripts.Add("MicrosoftAjaxSerialization.debug.js"); 790 scripts.Add("MicrosoftAjaxWebServices.js"); 791 scripts.Add("MicrosoftAjaxWebServices.debug.js"); 792 _splitFrameworkScript = scripts; 793 } 794 return _splitFrameworkScript; 795 } 796 } 797 798 [ 799 Browsable(false), 800 DefaultValue(true), 801 SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase") 802 ] 803 public bool SupportsPartialRendering { 804 get { 805 if (!EnablePartialRendering) { 806 // If the user doesn't even want partial rendering then 807 // we definitely don't support it. 808 return false; 809 } 810 return _supportsPartialRendering; 811 } 812 set { 813 if (!EnablePartialRendering) { 814 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotSetSupportsPartialRenderingWhenDisabled); 815 } 816 if (_initCompleted) { 817 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotChangeSupportsPartialRendering); 818 } 819 _supportsPartialRendering = value; 820 821 // Mark that this was explicitly set. We'll set this back to false if we 822 // explicitly set the value of this property. 823 _supportsPartialRenderingSetByUser = true; 824 } 825 } 826 827 [ 828 Browsable(false), 829 DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), 830 EditorBrowsable(EditorBrowsableState.Never) 831 ] 832 public override bool Visible { 833 get { 834 return base.Visible; 835 } 836 set { 837 throw new NotImplementedException(); 838 } 839 } 840 841 internal bool Zip { 842 get { 843 if (!_zipSet) { 844 _zip = HeaderUtility.IsEncodingInAcceptList(IPage.Request.Headers["Accept-encoding"], "gzip"); 845 _zipSet = true; 846 } 847 return _zip; 848 } 849 set { 850 _zip = value; 851 _zipSet = true; 852 } 853 } 854 855 [ 856 Category("Action"), 857 ResourceDescription("ScriptManager_AsyncPostBackError") 858 ] 859 public event EventHandler<AsyncPostBackErrorEventArgs> AsyncPostBackError { 860 add { 861 Events.AddHandler(AsyncPostBackErrorEvent, value); 862 } 863 remove { 864 Events.RemoveHandler(AsyncPostBackErrorEvent, value); 865 } 866 } 867 868 [ 869 Category("Action"), 870 ResourceDescription("ScriptManager_Navigate"), 871 ] 872 public event EventHandler<HistoryEventArgs> Navigate { 873 add { 874 Events.AddHandler(NavigateEvent, value); 875 } 876 remove { 877 Events.RemoveHandler(NavigateEvent, value); 878 } 879 } 880 881 [ 882 Category("Action"), 883 ResourceDescription("ScriptManager_ResolveCompositeScriptReference"), 884 ] 885 public event EventHandler<CompositeScriptReferenceEventArgs> ResolveCompositeScriptReference { 886 add { 887 Events.AddHandler(ResolveCompositeScriptReferenceEvent, value); 888 } 889 remove { 890 Events.RemoveHandler(ResolveCompositeScriptReferenceEvent, value); 891 } 892 } 893 894 [ 895 Category("Action"), 896 ResourceDescription("ScriptManager_ResolveScriptReference"), 897 ] 898 public event EventHandler<ScriptReferenceEventArgs> ResolveScriptReference { 899 add { 900 Events.AddHandler(ResolveScriptReferenceEvent, value); 901 } 902 remove { 903 Events.RemoveHandler(ResolveScriptReferenceEvent, value); 904 } 905 } 906 AddHistoryPoint(string key, string value)907 public void AddHistoryPoint(string key, string value) { 908 AddHistoryPoint(key, value, null); 909 } 910 AddHistoryPoint(string key, string value, string title)911 public void AddHistoryPoint(string key, string value, string title) { 912 PrepareNewHistoryPoint(); 913 SetStateValue(key, value); 914 SetPageTitle(title); 915 } 916 AddHistoryPoint(NameValueCollection state, string title)917 public void AddHistoryPoint(NameValueCollection state, string title) { 918 PrepareNewHistoryPoint(); 919 foreach (string key in state) { 920 SetStateValue(key, state[key]); 921 } 922 SetPageTitle(title); 923 } 924 AddFrameworkLoadedCheck()925 private void AddFrameworkLoadedCheck() { 926 // Add check for Sys to give better error message when the framework failed to load. 927 IPage.ClientScript.RegisterClientScriptBlock(typeof(ScriptManager), "FrameworkLoadedCheck", 928 ClientScriptManager.ClientScriptStart + "if (typeof(Sys) === 'undefined') throw new Error('" + 929 HttpUtility.JavaScriptStringEncode(AtlasWeb.ScriptManager_FrameworkFailedToLoad) + 930 "');\r\n" + ClientScriptManager.ClientScriptEnd, 931 addScriptTags: false); 932 } 933 AddFrameworkScript(ScriptReference frameworkScript, List<ScriptReferenceBase> scripts, bool webFormsWithoutAjax)934 private ScriptReferenceBase AddFrameworkScript(ScriptReference frameworkScript, List<ScriptReferenceBase> scripts, bool webFormsWithoutAjax) { 935 int scriptIndex = 0; 936 ScriptReferenceBase frameworkScriptBase = frameworkScript; 937 // PERF: If scripts.Count <= scriptIndex, then there are no user-specified scripts that might match 938 // the current framework script, so we don't even need to look, except for composite references. 939 if (scripts.Count != 0) { 940 // For each framework script we want to register, try to find it in the list of user-specified scripts. 941 // If it's there, move it to the top of the list. If it's not there, add it with our default settings. 942 // If multiple user-specified scripts match a framework script, the first one is moved to the top 943 // of the list, and later ones will be removed via RemoveDuplicates(). 944 945 // In the scenarios when MicrosoftWebForms.js is used (partial rendering is enabled), and MicrosoftAjax.js 946 // is disabled, MicrosoftWebForms.js cannot be used unless the users define and registere beforehand 947 // some equivalant script to MicrosoftAjax.js. So if there is MicrosoftWebForms.js in the list of 948 // user-specified scripts, we take no action and respect the order of the scripts that the users 949 // specified. Otherwise, we insert MicrosoftWebForms.js at the end of the user-specified script list. 950 string frameworkScriptName = frameworkScript.EffectiveResourceName; 951 string frameworkScriptPath = null; 952 if (String.IsNullOrEmpty(frameworkScriptName)) { 953 frameworkScriptPath = frameworkScript.EffectivePath; 954 } 955 Assembly frameworkAssembly = frameworkScript.GetAssembly(this); 956 for (int i = 0; i < scripts.Count; i++) { 957 ScriptReferenceBase script = scripts[i]; 958 ScriptReference sr = script as ScriptReference; 959 if ((sr != null) && 960 ((!String.IsNullOrEmpty(frameworkScriptName) && 961 (sr.EffectiveResourceName == frameworkScriptName)) && 962 (sr.GetAssembly(this) == frameworkAssembly) || 963 (!String.IsNullOrEmpty(frameworkScriptPath) && 964 sr.ScriptInfo.Path == frameworkScriptPath))) { 965 966 // If the found script is already on the top of the list, we dont need to remove then insert it back. 967 if (webFormsWithoutAjax || (i == 0)) { 968 script.AlwaysLoadBeforeUI = true; 969 return script; 970 } 971 972 frameworkScriptBase = script; 973 scripts.Remove(script); 974 break; 975 } 976 else { 977 CompositeScriptReference csr = script as CompositeScriptReference; 978 if (csr != null) { 979 bool found = false; 980 foreach (ScriptReference scriptReference in csr.Scripts) { 981 if (((!String.IsNullOrEmpty(frameworkScriptName) && 982 (scriptReference.EffectiveResourceName == frameworkScriptName)) && 983 (scriptReference.GetAssembly(this) == frameworkAssembly) || 984 (!String.IsNullOrEmpty(frameworkScriptPath) && 985 scriptReference.ScriptInfo.Path == frameworkScriptPath))) { 986 987 // If the found script is already on the top of the list, we dont need to remove then insert it back. 988 if (webFormsWithoutAjax || (i == 0)) { 989 script.AlwaysLoadBeforeUI = true; 990 return script; 991 } 992 // Even composite references are moved to the top if they contain an fx script. 993 frameworkScriptBase = script; 994 scripts.Remove(script); 995 found = true; 996 break; 997 } 998 } 999 if (found) { 1000 break; 1001 } 1002 } 1003 } 1004 } 1005 if (webFormsWithoutAjax) { 1006 scriptIndex = scripts.Count; 1007 } 1008 } 1009 1010 frameworkScriptBase.AlwaysLoadBeforeUI = true; 1011 scripts.Insert(scriptIndex, frameworkScriptBase); 1012 return frameworkScriptBase; 1013 } 1014 1015 // Called by ScriptManagerDesigner.GetScriptReferences() AddFrameworkScripts(List<ScriptReferenceBase> scripts)1016 internal void AddFrameworkScripts(List<ScriptReferenceBase> scripts) { 1017 // The 0 and 1 scriptIndex parameter to AddFrameworkScript() is how 1018 // we guarantee that the Atlas framework scripts get inserted 1019 // consecutively as the first script to be registered. If we add 1020 // more optional framework scripts we will have to increment the index 1021 // dynamically for each script so that there are no gaps between the 1022 // Atlas scripts. 1023 // Add MicrosoftAjaxApplicationServices.js first, 1024 // then MicrosoftAjaxWebForms.js, then MicrosoftAjax.js. So that the insert index is always at 0. 1025 // This is to fix the issue in DevDiv 664653, where there is only one composite script with both 1026 // MicrosoftAjaxWebForms.js and MicrosoftAjax.js, and inserting at index 1 is out of bound. 1027 AjaxFrameworkMode mode = AjaxFrameworkMode; 1028 if (mode != AjaxFrameworkMode.Disabled) { 1029 _appServicesInitializationScript = GetApplicationServicesInitializationScript(); 1030 // only add the script explicitly in enabled mode -- in explicit mode, we will 1031 // register the initialization script only after we find the reference that was included 1032 // explicitly. 1033 if ((mode == AjaxFrameworkMode.Enabled) && !String.IsNullOrEmpty(_appServicesInitializationScript)) { 1034 ScriptReference appServices = new ScriptReference("MicrosoftAjaxApplicationServices.js", this, this); 1035 _applicationServicesReference = AddFrameworkScript(appServices, scripts, false); 1036 } 1037 } 1038 if (SupportsPartialRendering && (mode != AjaxFrameworkMode.Disabled)) { 1039 ScriptReference atlasWebForms = new ScriptReference("MicrosoftAjaxWebForms.js", this, this); 1040 AddFrameworkScript(atlasWebForms, scripts, (AjaxFrameworkMode == AjaxFrameworkMode.Explicit)); 1041 } 1042 if (mode == AjaxFrameworkMode.Enabled) { 1043 ScriptReference atlasCore = new ScriptReference("MicrosoftAjax.js", this, this); 1044 atlasCore.IsDefiningSys = true; 1045 _scriptPathsDefiningSys.Add(atlasCore.EffectivePath); 1046 AddFrameworkScript(atlasCore, scripts, false); 1047 } 1048 } 1049 1050 // Add ScriptReferences from Scripts collections of ScriptManager and ScriptManagerProxies 1051 // Called by ScriptManagerDesigner.GetScriptReferences(). AddScriptCollections(List<ScriptReferenceBase> scripts, IEnumerable<ScriptManagerProxy> proxies)1052 internal void AddScriptCollections(List<ScriptReferenceBase> scripts, IEnumerable<ScriptManagerProxy> proxies) { 1053 if ((_compositeScript != null) && (_compositeScript.Scripts.Count != 0)) { 1054 _compositeScript.ClientUrlResolver = Control; 1055 _compositeScript.ContainingControl = this; 1056 _compositeScript.IsStaticReference = true; 1057 scripts.Add(_compositeScript); 1058 } 1059 // Register user-specified scripts from the ScriptManager 1060 // PERF: Use field directly to avoid creating List if not already created 1061 if (_scripts != null) { 1062 foreach (ScriptReference scriptReference in _scripts) { 1063 // Fix for Dev11 Bug # 406984 : When user explicitly adds the MicrosoftAjax.[debug].js OR MicrosoftAjaxCore.[debug].js, we want to mark them as defining Sys so that 1064 // we can register the FrameworkLoadedCheck scripts after them. 1065 if (scriptReference.IsAjaxFrameworkScript(this) && (scriptReference.Name.StartsWith("MicrosoftAjax.", StringComparison.OrdinalIgnoreCase) || scriptReference.Name.StartsWith("MicrosoftAjaxCore.", StringComparison.OrdinalIgnoreCase))) { 1066 scriptReference.IsDefiningSys = true; 1067 _scriptPathsDefiningSys.Add(scriptReference.EffectivePath); 1068 } 1069 scriptReference.ClientUrlResolver = Control; 1070 scriptReference.ContainingControl = this; 1071 scriptReference.IsStaticReference = true; 1072 scripts.Add(scriptReference); 1073 } 1074 } 1075 1076 // Register user-specified scripts from ScriptManagerProxy controls, if any 1077 if (proxies != null) { 1078 foreach (ScriptManagerProxy proxy in proxies) { 1079 proxy.CollectScripts(scripts); 1080 } 1081 } 1082 } 1083 CreateUniqueScriptKey()1084 internal string CreateUniqueScriptKey() { 1085 _uniqueScriptCounter++; 1086 return "UniqueScript_" + _uniqueScriptCounter.ToString(CultureInfo.InvariantCulture); 1087 } 1088 GetApplicationServicesInitializationScript()1089 private string GetApplicationServicesInitializationScript() { 1090 StringBuilder sb = null; 1091 1092 // Script that configures the application service proxies. For example setting the path properties. 1093 // If the services are disabled and none of the service manager properties are set, the sb will be null. 1094 ProfileServiceManager.ConfigureProfileService(ref sb, Context, this, _proxies); 1095 AuthenticationServiceManager.ConfigureAuthenticationService(ref sb, Context, this, _proxies); 1096 RoleServiceManager.ConfigureRoleService(ref sb, Context, this, _proxies); 1097 1098 if (sb != null && sb.Length > 0) { 1099 return sb.ToString(); 1100 } 1101 return null; 1102 } 1103 GetCurrent(Page page)1104 public static ScriptManager GetCurrent(Page page) { 1105 if (page == null) { 1106 throw new ArgumentNullException("page"); 1107 } 1108 1109 return page.Items[typeof(ScriptManager)] as ScriptManager; 1110 } 1111 1112 // AspNetHostingPermission attributes must be copied to this method, to satisfy FxCop rule 1113 // CA2114:MethodSecurityShouldBeASupersetOfType. 1114 [ 1115 ConfigurationPermission(SecurityAction.Assert, Unrestricted = true), 1116 SecurityCritical() 1117 ] GetCustomErrorsSectionWithAssert()1118 private static ICustomErrorsSection GetCustomErrorsSectionWithAssert() { 1119 return new CustomErrorsSectionWrapper( 1120 (CustomErrorsSection)WebConfigurationManager.GetSection("system.web/customErrors")); 1121 } 1122 1123 [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Depends on registered resources so order of execution is important.")] GetRegisteredArrayDeclarations()1124 public ReadOnlyCollection<RegisteredArrayDeclaration> GetRegisteredArrayDeclarations() { 1125 return new ReadOnlyCollection<RegisteredArrayDeclaration>(ScriptRegistration.ScriptArrays); 1126 } 1127 1128 [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Depends on registered resources so order of execution is important.")] GetRegisteredClientScriptBlocks()1129 public ReadOnlyCollection<RegisteredScript> GetRegisteredClientScriptBlocks() { 1130 // includes RegisterClientScriptBlock, RegisterClientScriptInclude, RegisterClientScriptResource 1131 return new ReadOnlyCollection<RegisteredScript>(ScriptRegistration.ScriptBlocks); 1132 } 1133 1134 [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Depends on registered resources so order of execution is important.")] GetRegisteredDisposeScripts()1135 public ReadOnlyCollection<RegisteredDisposeScript> GetRegisteredDisposeScripts() { 1136 return new ReadOnlyCollection<RegisteredDisposeScript>(ScriptRegistration.ScriptDisposes); 1137 } 1138 1139 [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Depends on registered resources so order of execution is important.")] GetRegisteredExpandoAttributes()1140 public ReadOnlyCollection<RegisteredExpandoAttribute> GetRegisteredExpandoAttributes() { 1141 return new ReadOnlyCollection<RegisteredExpandoAttribute>(ScriptRegistration.ScriptExpandos); 1142 } 1143 1144 [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Depends on registered resources so order of execution is important.")] GetRegisteredHiddenFields()1145 public ReadOnlyCollection<RegisteredHiddenField> GetRegisteredHiddenFields() { 1146 return new ReadOnlyCollection<RegisteredHiddenField>(ScriptRegistration.ScriptHiddenFields); 1147 } 1148 1149 [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Depends on registered resources so order of execution is important.")] GetRegisteredOnSubmitStatements()1150 public ReadOnlyCollection<RegisteredScript> GetRegisteredOnSubmitStatements() { 1151 return new ReadOnlyCollection<RegisteredScript>(ScriptRegistration.ScriptSubmitStatements); 1152 } 1153 1154 [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Depends on registered resources so order of execution is important.")] GetRegisteredStartupScripts()1155 public ReadOnlyCollection<RegisteredScript> GetRegisteredStartupScripts() { 1156 return new ReadOnlyCollection<RegisteredScript>(ScriptRegistration.ScriptStartupBlocks); 1157 } 1158 GetScriptResourceUrl(string resourceName, Assembly assembly)1159 internal string GetScriptResourceUrl(string resourceName, Assembly assembly) { 1160 return ScriptResourceHandler.GetScriptResourceUrl( 1161 assembly, 1162 resourceName, 1163 (EnableScriptLocalization ? CultureInfo.CurrentUICulture : CultureInfo.InvariantCulture), 1164 Zip); 1165 } 1166 1167 [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", 1168 Justification = "Getting the state string is a heavy operation.")] GetStateString()1169 public string GetStateString() { 1170 if (EnableSecureHistoryState) { 1171 StatePersister persister = new StatePersister(Page); 1172 return persister.Serialize(_initialState); 1173 } 1174 else if (_initialState == null) { 1175 return String.Empty; 1176 } 1177 else { 1178 StringBuilder sb = new StringBuilder(); 1179 bool first = true; 1180 foreach (DictionaryEntry kvp in _initialState) { 1181 if (!first) { 1182 sb.Append('&'); 1183 } 1184 else { 1185 first = false; 1186 } 1187 sb.Append(HttpUtility.UrlEncode((string)kvp.Key)); 1188 sb.Append('='); 1189 sb.Append(HttpUtility.UrlEncode((string)kvp.Value)); 1190 } 1191 return sb.ToString(); 1192 } 1193 } 1194 LoadHistoryState(string serverState)1195 private void LoadHistoryState(string serverState) { 1196 NameValueCollection state; 1197 if (String.IsNullOrEmpty(serverState)) { 1198 _initialState = new Hashtable(StringComparer.Ordinal); 1199 state = new NameValueCollection(); 1200 } 1201 else if (EnableSecureHistoryState) { 1202 StatePersister persister = new StatePersister(Page); 1203 _initialState = (Hashtable)persister.Deserialize(serverState); 1204 1205 state = new NameValueCollection(); 1206 foreach (DictionaryEntry entry in _initialState) { 1207 state.Add((string)entry.Key, (string)entry.Value); 1208 } 1209 } 1210 else { 1211 state = HttpUtility.ParseQueryString(serverState); 1212 _initialState = new Hashtable(state.Count, StringComparer.Ordinal); 1213 1214 foreach (string key in state) { 1215 _initialState.Add(key, state[key]); 1216 } 1217 } 1218 HistoryEventArgs args = new HistoryEventArgs(state); 1219 RaiseNavigate(args); 1220 } 1221 LoadPostData(string postDataKey, NameValueCollection postCollection)1222 protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) { 1223 if (IsInAsyncPostBack) { 1224 PageRequestManager.LoadPostData(postDataKey, postCollection); 1225 } 1226 else if (EnableHistory && (AjaxFrameworkMode != AjaxFrameworkMode.Disabled)) { 1227 // get current state string if it exists 1228 string serverState = postCollection[postDataKey]; 1229 LoadHistoryState(serverState); 1230 } 1231 1232 return false; 1233 } 1234 NeedToLoadBeforeUI(ScriptReference script, AjaxFrameworkMode ajaxMode)1235 private bool NeedToLoadBeforeUI(ScriptReference script, AjaxFrameworkMode ajaxMode) { 1236 return script.IsFromSystemWeb() || 1237 (ajaxMode == AjaxFrameworkMode.Explicit && 1238 (script.IsAjaxFrameworkScript(this) && SplitFrameworkScripts.Contains(script.EffectiveResourceName))); 1239 } 1240 1241 [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")] OnAsyncPostBackError(AsyncPostBackErrorEventArgs e)1242 protected internal virtual void OnAsyncPostBackError(AsyncPostBackErrorEventArgs e) { 1243 EventHandler<AsyncPostBackErrorEventArgs> handler = 1244 (EventHandler<AsyncPostBackErrorEventArgs>)Events[AsyncPostBackErrorEvent]; 1245 if (handler != null) { 1246 handler(this, e); 1247 } 1248 } 1249 1250 [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")] OnInit(EventArgs e)1251 protected internal override void OnInit(EventArgs e) { 1252 base.OnInit(e); 1253 1254 if (!DesignMode) { 1255 // Ensure the current ajax framework assembly has a higher version number than System.Web.Extensions. 1256 Assembly ajaxFrameworkAssembly = AjaxFrameworkAssembly; 1257 if ((ajaxFrameworkAssembly != null) && (ajaxFrameworkAssembly != AssemblyCache.SystemWebExtensions)) { 1258 if (AssemblyCache.GetVersion(ajaxFrameworkAssembly) <= 1259 AssemblyCache.GetVersion(AssemblyCache.SystemWebExtensions)) { 1260 // Must have a higher version number 1261 throw new InvalidOperationException( 1262 String.Format(CultureInfo.CurrentUICulture, AtlasWeb.ScriptManager_MustHaveGreaterVersion, 1263 ajaxFrameworkAssembly, AssemblyCache.GetVersion(AssemblyCache.SystemWebExtensions))); 1264 } 1265 } 1266 1267 IPage page = IPage; 1268 ScriptManager existingInstance = ScriptManager.GetCurrent(Page); 1269 1270 if (existingInstance != null) { 1271 throw new InvalidOperationException(AtlasWeb.ScriptManager_OnlyOneScriptManager); 1272 } 1273 page.Items[typeof(IScriptManager)] = this; 1274 page.Items[typeof(ScriptManager)] = this; 1275 1276 page.InitComplete += OnPageInitComplete; 1277 page.PreRenderComplete += OnPagePreRenderComplete; 1278 1279 if (page.IsPostBack) { 1280 _isInAsyncPostBack = PageRequestManager.IsAsyncPostBackRequest(page.Request); 1281 } 1282 1283 // Delegate to PageRequestManager to hook up error handling for async posts 1284 PageRequestManager.OnInit(); 1285 1286 page.PreRender += ScriptControlManager.OnPagePreRender; 1287 } 1288 } 1289 RaiseNavigate(HistoryEventArgs e)1290 private void RaiseNavigate(HistoryEventArgs e) { 1291 EventHandler<HistoryEventArgs> handler = (EventHandler<HistoryEventArgs>)Events[NavigateEvent]; 1292 if (handler != null) { 1293 handler(this, e); 1294 } 1295 foreach (ScriptManagerProxy proxy in Proxies) { 1296 handler = proxy.NavigateEvent; 1297 if (handler != null) { 1298 handler(this, e); 1299 } 1300 } 1301 } 1302 OnPagePreRenderComplete(object sender, EventArgs e)1303 private void OnPagePreRenderComplete(object sender, EventArgs e) { 1304 _preRenderCompleted = true; 1305 if (!IsInAsyncPostBack) { 1306 if (SupportsPartialRendering && (AjaxFrameworkMode != AjaxFrameworkMode.Disabled)) { 1307 // Force ASP.NET to include the __doPostBack function. If we don't do 1308 // this then on the client we might not be able to override the function 1309 // (since it won't be defined). 1310 // We also need to force it to include the ASP.NET WebForms.js since it 1311 // has other required functionality. 1312 IPage.ClientScript.GetPostBackEventReference(new PostBackOptions(this, null, null, false, false, false, false, true, null)); 1313 } 1314 // on GET request we register the glob block... 1315 RegisterGlobalizationScriptBlock(); 1316 // all script references, declared and from script controls... 1317 RegisterScripts(); 1318 // and all service references. 1319 RegisterServices(); 1320 } 1321 else { 1322 // on async postbacks we only need to register script control references and inline references. 1323 RegisterScripts(); 1324 if (EnableHistory && (AjaxFrameworkMode != AjaxFrameworkMode.Disabled)) { 1325 // Send empty object as null to the client 1326 if ((_initialState != null) && (_initialState.Count == 0)) { 1327 _initialState = null; 1328 } 1329 if (_newPointCreated) { 1330 RegisterDataItem(this, GetStateString(), false); 1331 } 1332 } 1333 } 1334 } 1335 OnPageInitComplete(object sender, EventArgs e)1336 private void OnPageInitComplete(object sender, EventArgs e) { 1337 if (IPage.IsPostBack) { 1338 if (IsInAsyncPostBack && !SupportsPartialRendering) { 1339 throw new InvalidOperationException(AtlasWeb.ScriptManager_AsyncPostBackNotInPartialRenderingMode); 1340 } 1341 } 1342 1343 _initCompleted = true; 1344 1345 if (EnableHistory && (AjaxFrameworkMode != AjaxFrameworkMode.Disabled)) { 1346 RegisterAsyncPostBackControl(this); 1347 if (IPage.IsPostBack) { 1348 // Currently navigation is the only postback that ScriptManager handles 1349 // so we can assume that if the event target is the script manager, then 1350 // we're navigating. 1351 _isNavigating = IPage.Request[System.Web.UI.Page.postEventSourceID] == this.UniqueID; 1352 } 1353 } 1354 } 1355 1356 [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")] OnPreRender(EventArgs e)1357 protected internal override void OnPreRender(EventArgs e) { 1358 base.OnPreRender(e); 1359 1360 if (IsInAsyncPostBack) { 1361 PageRequestManager.OnPreRender(); 1362 } 1363 } 1364 1365 [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")] OnResolveCompositeScriptReference(CompositeScriptReferenceEventArgs e)1366 protected virtual void OnResolveCompositeScriptReference(CompositeScriptReferenceEventArgs e) { 1367 EventHandler<CompositeScriptReferenceEventArgs> handler = 1368 (EventHandler<CompositeScriptReferenceEventArgs>)Events[ResolveCompositeScriptReferenceEvent]; 1369 if (handler != null) { 1370 handler(this, e); 1371 } 1372 } 1373 1374 [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")] OnResolveScriptReference(ScriptReferenceEventArgs e)1375 protected virtual void OnResolveScriptReference(ScriptReferenceEventArgs e) { 1376 EventHandler<ScriptReferenceEventArgs> handler = 1377 (EventHandler<ScriptReferenceEventArgs>)Events[ResolveScriptReferenceEvent]; 1378 if (handler != null) { 1379 handler(this, e); 1380 } 1381 } 1382 PrepareNewHistoryPoint()1383 private void PrepareNewHistoryPoint() { 1384 if (!EnableHistory) { 1385 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotAddHistoryPointWithHistoryDisabled); 1386 } 1387 if (!IsInAsyncPostBack) { 1388 throw new InvalidOperationException(AtlasWeb.ScriptManager_CannotAddHistoryPointOutsideOfAsyncPostBack); 1389 } 1390 _newPointCreated = true; 1391 if (_initialState == null) { 1392 _initialState = new Hashtable(StringComparer.Ordinal); 1393 } 1394 } 1395 1396 [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", 1397 Justification = "Matches IPostBackEventHandler interface.")] RaisePostBackEvent(string eventArgument)1398 protected virtual void RaisePostBackEvent(string eventArgument) { 1399 LoadHistoryState(eventArgument); 1400 } 1401 1402 [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", 1403 Justification = "Matches IPostBackDataHandler interface.")] RaisePostDataChangedEvent()1404 protected virtual void RaisePostDataChangedEvent() { 1405 } 1406 1407 // 1408 1409 1410 1411 1412 [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The overload specifically exists to strengthen the support for passing in a Page parameter.")] RegisterArrayDeclaration(Page page, string arrayName, string arrayValue)1413 public static void RegisterArrayDeclaration(Page page, string arrayName, string arrayValue) { 1414 ScriptRegistrationManager.RegisterArrayDeclaration(page, arrayName, arrayValue); 1415 } 1416 RegisterArrayDeclaration(Control control, string arrayName, string arrayValue)1417 public static void RegisterArrayDeclaration(Control control, string arrayName, string arrayValue) { 1418 ScriptRegistrationManager.RegisterArrayDeclaration(control, arrayName, arrayValue); 1419 } 1420 1421 // Registers a control as causing an async postback instead of a regular postback 1422 [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] RegisterAsyncPostBackControl(Control control)1423 public void RegisterAsyncPostBackControl(Control control) { 1424 PageRequestManager.RegisterAsyncPostBackControl(control); 1425 } 1426 1427 // Internal virtual for testing. Cannot mock static RegisterClientScriptBlock(). RegisterClientScriptBlockInternal(Control control, Type type, string key, string script, bool addScriptTags)1428 internal virtual void RegisterClientScriptBlockInternal(Control control, Type type, string key, string script, bool addScriptTags) { 1429 RegisterClientScriptBlock(control, type, key, script, addScriptTags); 1430 } 1431 1432 [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The overload specifically exists to strengthen the support for passing in a Page parameter.")] RegisterClientScriptBlock(Page page, Type type, string key, string script, bool addScriptTags)1433 public static void RegisterClientScriptBlock(Page page, Type type, string key, string script, bool addScriptTags) { 1434 ScriptRegistrationManager.RegisterClientScriptBlock(page, type, key, script, addScriptTags); 1435 } 1436 RegisterClientScriptBlock(Control control, Type type, string key, string script, bool addScriptTags)1437 public static void RegisterClientScriptBlock(Control control, Type type, string key, string script, bool addScriptTags) { 1438 ScriptRegistrationManager.RegisterClientScriptBlock(control, type, key, script, addScriptTags); 1439 } 1440 1441 // Internal virtual for testing. Cannot mock static RegisterClientScriptInclude(). RegisterClientScriptIncludeInternal(Control control, Type type, string key, string url)1442 internal virtual void RegisterClientScriptIncludeInternal(Control control, Type type, string key, string url) { 1443 RegisterClientScriptInclude(control, type, key, url); 1444 } 1445 1446 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", 1447 Justification = "Needs to take same parameters as ClientScriptManager.RegisterClientScriptInclude()." + 1448 "We could provide an overload that takes a System.Uri parameter, but then FxCop rule " + 1449 "StringUriOverloadsCallSystemUriOverloads would require that the string overload call the Uri overload. " + 1450 "But we cannot do this, because the ClientScriptManager API allows any string, even invalid Uris. " + 1451 "We cannot start throwing exceptions on input we previously passed to the browser. So it does not make " + 1452 "sense to add an overload that takes System.Uri.")] 1453 [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The overload specifically exists to strengthen the support for passing in a Page parameter.")] RegisterClientScriptInclude(Page page, Type type, string key, string url)1454 public static void RegisterClientScriptInclude(Page page, Type type, string key, string url) { 1455 ScriptRegistrationManager.RegisterClientScriptInclude(page, type, key, url); 1456 } 1457 1458 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", 1459 Justification = "Needs to take same parameters as ClientScriptManager.RegisterClientScriptInclude()." + 1460 "We could provide an overload that takes a System.Uri parameter, but then FxCop rule " + 1461 "StringUriOverloadsCallSystemUriOverloads would require that the string overload call the Uri overload. " + 1462 "But we cannot do this, because the ClientScriptManager API allows any string, even invalid Uris. " + 1463 "We cannot start throwing exceptions on input we previously passed to the browser. So it does not make " + 1464 "sense to add an overload that takes System.Uri.")] RegisterClientScriptInclude(Control control, Type type, string key, string url)1465 public static void RegisterClientScriptInclude(Control control, Type type, string key, string url) { 1466 ScriptRegistrationManager.RegisterClientScriptInclude(control, type, key, url); 1467 } 1468 1469 [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The overload specifically exists to strengthen the support for passing in a Page parameter.")] RegisterClientScriptResource(Page page, Type type, string resourceName)1470 public static void RegisterClientScriptResource(Page page, Type type, string resourceName) { 1471 ScriptRegistrationManager.RegisterClientScriptResource(page, type, resourceName); 1472 } 1473 RegisterClientScriptResource(Control control, Type type, string resourceName)1474 public static void RegisterClientScriptResource(Control control, Type type, string resourceName) { 1475 ScriptRegistrationManager.RegisterClientScriptResource(control, type, resourceName); 1476 } 1477 1478 // Only if we have a script manager on the page and we can resolve a path for the resource definition 1479 // then can we add it to the script definitions so script references will be de-duped TryRegisterNamedClientScriptResourceUsingScriptReference(Page page, string resourceName)1480 private static bool TryRegisterNamedClientScriptResourceUsingScriptReference(Page page, string resourceName) { 1481 if (page != null) { 1482 ScriptManager sm = GetCurrent(page); 1483 ScriptResourceDefinition def = ScriptManager.ScriptResourceMapping.GetDefinition(resourceName); 1484 if (sm != null && def != null) { 1485 sm.Scripts.Add(new ScriptReference() { Name = resourceName }); 1486 return true; 1487 } 1488 } 1489 1490 return false; 1491 } 1492 RegisterNamedClientScriptResource(Control control, string resourceName)1493 public static void RegisterNamedClientScriptResource(Control control, string resourceName) { 1494 // Try to use ScriptManager Scripts collection if we can(for de-dupe logic), otherwise fall back to RegisterClientScriptResource 1495 if (control != null && TryRegisterNamedClientScriptResourceUsingScriptReference(control.Page, resourceName)) { 1496 return; 1497 } 1498 RegisterClientScriptResource(control, typeof(ScriptManager), resourceName); 1499 } 1500 RegisterNamedClientScriptResource(Page page, string resourceName)1501 public static void RegisterNamedClientScriptResource(Page page, string resourceName) { 1502 // Try to use ScriptManager Scripts collection if we can(for de-dupe logic), otherwise fall back to RegisterClientScriptResource 1503 if (TryRegisterNamedClientScriptResourceUsingScriptReference(page, resourceName)) { 1504 return; 1505 } 1506 RegisterClientScriptResource(page, typeof(ScriptManager), resourceName); 1507 } 1508 RegisterDataItem(Control control, string dataItem)1509 public void RegisterDataItem(Control control, string dataItem) { 1510 RegisterDataItem(control, dataItem, false); 1511 } 1512 RegisterDataItem(Control control, string dataItem, bool isJsonSerialized)1513 public void RegisterDataItem(Control control, string dataItem, bool isJsonSerialized) { 1514 PageRequestManager.RegisterDataItem(control, dataItem, isJsonSerialized); 1515 } 1516 RegisterDispose(Control control, string disposeScript)1517 public void RegisterDispose(Control control, string disposeScript) { 1518 if (SupportsPartialRendering && (AjaxFrameworkMode != AjaxFrameworkMode.Disabled)) { 1519 // DevDiv Bugs 124041: Do not register if SupportsPartialRendering=false 1520 // It would cause a script error since PageRequestManager will not exist on the client. 1521 ScriptRegistration.RegisterDispose(control, disposeScript); 1522 } 1523 } 1524 RegisterExpandoAttribute(Control control, string controlId, string attributeName, string attributeValue, bool encode)1525 public static void RegisterExpandoAttribute(Control control, string controlId, string attributeName, string attributeValue, bool encode) { 1526 ScriptRegistrationManager.RegisterExpandoAttribute(control, controlId, attributeName, attributeValue, encode); 1527 } 1528 1529 [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] 1530 public void RegisterExtenderControl<TExtenderControl>(TExtenderControl extenderControl, Control targetControl) 1531 where TExtenderControl : Control, IExtenderControl { 1532 ScriptControlManager.RegisterExtenderControl(extenderControl, targetControl); 1533 } 1534 RegisterGlobalizationScriptBlock()1535 private void RegisterGlobalizationScriptBlock() { 1536 if (EnableScriptGlobalization && (AjaxFrameworkMode != AjaxFrameworkMode.Disabled)) { 1537 Tuple<String, String> entry = ClientCultureInfo.GetClientCultureScriptBlock(CultureInfo.CurrentCulture); 1538 if ((entry != null) && !String.IsNullOrEmpty(entry.Item1)) { 1539 if (IsDebuggingEnabled && (AjaxFrameworkMode == AjaxFrameworkMode.Explicit)) { 1540 string script = "Type._checkDependency('MicrosoftAjaxGlobalization.js', 'ScriptManager.EnableScriptGlobalization');\r\n"; 1541 ScriptRegistrationManager.RegisterStartupScript(this, typeof(ScriptManager), "CultureInfoScriptCheck", script, true); 1542 } 1543 ScriptRegistrationManager.RegisterClientScriptBlock(this, typeof(ScriptManager), "CultureInfo", entry.Item1, true); 1544 if (!String.IsNullOrEmpty(entry.Item2)) { 1545 ScriptReference reference = new ScriptReference(entry.Item2, null); 1546 #pragma warning disable 618 1547 // ScriptPath is obsolete but still functional 1548 reference.IgnoreScriptPath = true; 1549 #pragma warning restore 618 1550 reference.AlwaysLoadBeforeUI = true; 1551 // added to Script collection instead of directly registered so that it goes through 1552 // script resolution, and is resolved for debug/release version, etc. 1553 // It can also be explicitly declared to customize it. 1554 // e.g. <asp:ScriptReference Name="Date.HijriCalendar.js" Path="foo.js"/> 1555 Scripts.Add(reference); 1556 } 1557 } 1558 } 1559 } 1560 1561 [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The overload specifically exists to strengthen the support for passing in a Page parameter.")] RegisterHiddenField(Page page, string hiddenFieldName, string hiddenFieldInitialValue)1562 public static void RegisterHiddenField(Page page, string hiddenFieldName, string hiddenFieldInitialValue) { 1563 ScriptRegistrationManager.RegisterHiddenField(page, hiddenFieldName, hiddenFieldInitialValue); 1564 } 1565 RegisterHiddenField(Control control, string hiddenFieldName, string hiddenFieldInitialValue)1566 public static void RegisterHiddenField(Control control, string hiddenFieldName, string hiddenFieldInitialValue) { 1567 ScriptRegistrationManager.RegisterHiddenField(control, hiddenFieldName, hiddenFieldInitialValue); 1568 } 1569 1570 [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The overload specifically exists to strengthen the support for passing in a Page parameter.")] RegisterOnSubmitStatement(Page page, Type type, string key, string script)1571 public static void RegisterOnSubmitStatement(Page page, Type type, string key, string script) { 1572 ScriptRegistrationManager.RegisterOnSubmitStatement(page, type, key, script); 1573 } 1574 RegisterOnSubmitStatement(Control control, Type type, string key, string script)1575 public static void RegisterOnSubmitStatement(Control control, Type type, string key, string script) { 1576 ScriptRegistrationManager.RegisterOnSubmitStatement(control, type, key, script); 1577 } 1578 1579 [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] 1580 public void RegisterScriptControl<TScriptControl>(TScriptControl scriptControl) 1581 where TScriptControl : Control, IScriptControl { 1582 ScriptControlManager.RegisterScriptControl(scriptControl); 1583 } 1584 1585 [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] RegisterScriptDescriptors(IExtenderControl extenderControl)1586 public void RegisterScriptDescriptors(IExtenderControl extenderControl) { 1587 ScriptControlManager.RegisterScriptDescriptors(extenderControl); 1588 } 1589 1590 [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] RegisterScriptDescriptors(IScriptControl scriptControl)1591 public void RegisterScriptDescriptors(IScriptControl scriptControl) { 1592 ScriptControlManager.RegisterScriptDescriptors(scriptControl); 1593 } 1594 1595 // Registers a control as causing a regular postback instead of an async postback 1596 [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] RegisterPostBackControl(Control control)1597 public void RegisterPostBackControl(Control control) { 1598 PageRequestManager.RegisterPostBackControl(control); 1599 } 1600 GetEffectivePath(ScriptReferenceBase scriptRef)1601 private static string GetEffectivePath(ScriptReferenceBase scriptRef) { 1602 string effectivePath = scriptRef.Path; 1603 if (String.IsNullOrEmpty(effectivePath)) { 1604 // Also try using Effective path for ScriptReferences, which is the case for framework scripts 1605 ScriptReference sref = scriptRef as ScriptReference; 1606 if (sref != null) { 1607 effectivePath = sref.EffectivePath; 1608 } 1609 } 1610 return effectivePath; 1611 } 1612 1613 // If bundling is supported, look for references to bundles, eliminate duplicates, and get the true bundle url for the reference ProcessBundleReferences(List<ScriptReferenceBase> scripts)1614 internal List<ScriptReferenceBase> ProcessBundleReferences(List<ScriptReferenceBase> scripts) { 1615 // If we have a bundle resolver, look through all the scripts and see which are bundles 1616 object resolver = BundleReflectionHelper.BundleResolver; 1617 if (resolver != null) { 1618 HashSet<string> virtualPathsInBundles = new HashSet<string>(StringComparer.OrdinalIgnoreCase); 1619 1620 // For each bundle, expand and remember every path inside 1621 foreach (ScriptReferenceBase scriptRef in scripts) { 1622 string effectivePath = GetEffectivePath(scriptRef); 1623 if (BundleReflectionHelper.IsBundleVirtualPath(effectivePath)) { 1624 scriptRef.IsBundleReference = true; 1625 1626 IEnumerable<string> bundleContents = BundleReflectionHelper.GetBundleContents(effectivePath); 1627 if (bundleContents != null) { 1628 foreach (string path in bundleContents) { 1629 virtualPathsInBundles.Add(path); 1630 if (_scriptPathsDefiningSys.Contains(path)) { 1631 scriptRef.IsDefiningSys = true; 1632 } 1633 } 1634 } 1635 } 1636 } 1637 1638 // No bundles so we are done 1639 if (virtualPathsInBundles.Count == 0) { 1640 return scripts; 1641 } 1642 1643 // Go through the scripts and remove any references to scripts inside of bundles 1644 List<ScriptReferenceBase> collapsedReferences = new List<ScriptReferenceBase>(); 1645 foreach (ScriptReferenceBase scriptRef in scripts) { 1646 string effectivePath = GetEffectivePath(scriptRef); 1647 if (scriptRef.IsBundleReference) { 1648 collapsedReferences.Add(scriptRef); 1649 } 1650 else { 1651 if (!virtualPathsInBundles.Contains(effectivePath)) { 1652 collapsedReferences.Add(scriptRef); 1653 } 1654 } 1655 } 1656 1657 return collapsedReferences; 1658 } 1659 1660 return scripts; 1661 } 1662 RegisterScripts()1663 private void RegisterScripts() { 1664 List<ScriptReferenceBase> scripts = new List<ScriptReferenceBase>(); 1665 1666 // Add ScriptReferences from Scripts collections of ScriptManager and ScriptManagerProxies 1667 // PERF: Use _proxies field directly to avoid creating List if not already created 1668 AddScriptCollections(scripts, _proxies); 1669 1670 // Add ScriptReferences registered by ScriptControls and ExtenderControls 1671 ScriptControlManager.AddScriptReferences(scripts); 1672 1673 // Inject Atlas Framework scripts 1674 AddFrameworkScripts(scripts); 1675 1676 // Allow custom resolve work to happen 1677 foreach (ScriptReferenceBase script in scripts) { 1678 ScriptReference sr = script as ScriptReference; 1679 if (sr != null) { 1680 OnResolveScriptReference(new ScriptReferenceEventArgs(sr)); 1681 } 1682 else { 1683 CompositeScriptReference csr = script as CompositeScriptReference; 1684 if (csr != null) { 1685 OnResolveCompositeScriptReference(new CompositeScriptReferenceEventArgs(csr)); 1686 } 1687 } 1688 } 1689 // Remove duplicate Name+Assembly references 1690 List<ScriptReferenceBase> uniqueScripts = RemoveDuplicates(scripts, AjaxFrameworkMode, 1691 LoadScriptsBeforeUI, (IsInAsyncPostBack ? null : IPage.ClientScript), 1692 ref _applicationServicesReference); 1693 1694 // Remove any scripts that are contained inside of any bundles 1695 uniqueScripts = ProcessBundleReferences(uniqueScripts); 1696 1697 // Register the final list of unique scripts 1698 RegisterUniqueScripts(uniqueScripts); 1699 } 1700 RegisterUniqueScripts(List<ScriptReferenceBase> uniqueScripts)1701 private void RegisterUniqueScripts(List<ScriptReferenceBase> uniqueScripts) { 1702 bool loadCheckRegistered = !(IsDebuggingEnabled && !IsInAsyncPostBack); 1703 bool hasAppServicesScript = !String.IsNullOrEmpty(_appServicesInitializationScript); 1704 bool loadScriptsBeforeUI = this.LoadScriptsBeforeUI; 1705 AjaxFrameworkMode mode = AjaxFrameworkMode; 1706 foreach (ScriptReferenceBase script in uniqueScripts) { 1707 string url = script.GetUrl(this, Zip); 1708 string key = url; 1709 if (loadScriptsBeforeUI || script.AlwaysLoadBeforeUI) { 1710 RegisterClientScriptIncludeInternal(script.ContainingControl, typeof(ScriptManager), key, url); 1711 } 1712 else { 1713 // this method of building the script tag matches exactly ClientScriptManager.RegisterClientScriptInclude 1714 string scriptTag = "\r\n<script src=\"" + HttpUtility.HtmlAttributeEncode(url) + "\" type=\"text/javascript\"></script>"; 1715 RegisterStartupScriptInternal(script.ContainingControl, typeof(ScriptManager), url, scriptTag, false); 1716 } 1717 1718 RegisterFallbackScript(script, key); 1719 1720 // configure app services and check framework right after framework script is included & before other scripts 1721 if ((!loadCheckRegistered || hasAppServicesScript) && script.IsAjaxFrameworkScript(this) && (mode != AjaxFrameworkMode.Disabled)) { 1722 // In debug mode, detect if the framework loaded properly before we reference Sys in any way. 1723 if (!loadCheckRegistered && script.IsDefiningSys) { 1724 AddFrameworkLoadedCheck(); 1725 loadCheckRegistered = true; 1726 } 1727 1728 if (hasAppServicesScript && (script == _applicationServicesReference)) { 1729 this.IPage.ClientScript.RegisterClientScriptBlock(typeof(ScriptManager), 1730 "AppServicesConfig", 1731 _appServicesInitializationScript, 1732 true); 1733 hasAppServicesScript = false; 1734 } 1735 } 1736 } 1737 // note: in explicit mode it is possible at this point that hasAppServicesScript is still true 1738 // because the dev did not reference appservices.js. By design, we will treat this scenario 1739 // as if app services are not intended to be used. 1740 // In Enabled mode it isn't possible that the script is not included and there is init script, 1741 // because we add it if it doesn't already exist. 1742 } 1743 1744 /// <summary> 1745 /// Registers a script that causes the local copy of a script to load in the event the Cdn is unavailable. 1746 /// </summary> 1747 /// <param name="script"></param> RegisterFallbackScript(ScriptReferenceBase script, string key)1748 private void RegisterFallbackScript(ScriptReferenceBase script, string key) { 1749 if (!EnableCdn || !EnableCdnFallback) { 1750 return; 1751 } 1752 1753 // If we are using Cdn, register a fallback script for the ScriptReference it is available. 1754 var scriptReference = script as ScriptReference; 1755 if (scriptReference != null) { 1756 var scriptInfo = scriptReference.ScriptInfo; 1757 if (!String.IsNullOrEmpty(scriptInfo.LoadSuccessExpression)) { 1758 string fallbackPath = scriptReference.GetUrlInternal(this, Zip, useCdnPath: false); 1759 if (String.IsNullOrEmpty(fallbackPath)) { 1760 return; 1761 } 1762 1763 if (_isInAsyncPostBack) { 1764 // For async postbacks, we need to register the script with the ScriptRegistrationManager. document.write won't work. 1765 ScriptRegistrationManager.RegisterFallbackScriptForAjaxPostbacks(script.ContainingControl, typeof(ScriptManager), 1766 key, scriptInfo.LoadSuccessExpression, fallbackPath); 1767 } 1768 else { 1769 RegisterClientScriptBlockInternal(script.ContainingControl, typeof(ScriptManager), scriptInfo.LoadSuccessExpression, 1770 String.Format(CultureInfo.InvariantCulture, "({0})||document.write('<script type=\"text/javascript\" src=\"{1}\"><\\/script>');", scriptInfo.LoadSuccessExpression, fallbackPath), 1771 addScriptTags: true); 1772 } 1773 } 1774 } 1775 } 1776 RegisterServices()1777 private void RegisterServices() { 1778 // Do not attempt to resolve inline service references on PageMethod requests. 1779 if (_services != null) { 1780 foreach (ServiceReference serviceReference in _services) { 1781 serviceReference.Register(this, this); 1782 } 1783 } 1784 1785 if (_proxies != null) { 1786 foreach (ScriptManagerProxy proxy in _proxies) { 1787 proxy.RegisterServices(this); 1788 } 1789 } 1790 1791 if (EnablePageMethods) { 1792 string pageMethods = PageClientProxyGenerator.GetClientProxyScript(Context, IPage, IsDebuggingEnabled); 1793 if (!String.IsNullOrEmpty(pageMethods)) { 1794 RegisterClientScriptBlockInternal(this, typeof(ScriptManager), pageMethods, pageMethods, true); 1795 } 1796 } 1797 } 1798 RegisterResourceWithClientScriptManager(IClientScriptManager clientScriptManager, Assembly assembly, String key)1799 private static void RegisterResourceWithClientScriptManager(IClientScriptManager clientScriptManager, Assembly assembly, String key) { 1800 // Tells the ClientScriptManager that ScriptManager has registered an assembly resource, 'key' from 'assembly', 1801 // so that it does not register it again if it were registered with RegisterClientScriptResource. This allows 1802 // script references to override them, allowing devs to take advantage of setting a 'path' to override them or 1803 // to use ScriptCombining to combine them. 1804 // RegisteredResourcesToSuppress is a Dictionary of Dictionaries. The outer dictionary key is assembly, 1805 // the inner key is resource. 1806 Dictionary<Assembly, Dictionary<String, Object>> suppressedResources = clientScriptManager.RegisteredResourcesToSuppress; 1807 Debug.Assert(suppressedResources != null, "ClientScriptManager.RegisteredResourcesToSuppress is not expected to return null."); 1808 Dictionary<String, Object> resourcesForAssembly; 1809 if (!suppressedResources.TryGetValue(assembly, out resourcesForAssembly)) { 1810 resourcesForAssembly = new Dictionary<String, Object>(); 1811 suppressedResources[assembly] = resourcesForAssembly; 1812 } 1813 resourcesForAssembly[key] = true; 1814 } 1815 1816 // Called by ScriptManagerDesigner.GetScriptReferences(). RemoveDuplicates(List<ScriptReferenceBase> scripts, AjaxFrameworkMode ajaxFrameworkMode, bool loadScriptsBeforeUI, IClientScriptManager clientScriptManager, ref ScriptReferenceBase applicationServicesReference)1817 internal List<ScriptReferenceBase> RemoveDuplicates(List<ScriptReferenceBase> scripts, 1818 AjaxFrameworkMode ajaxFrameworkMode, bool loadScriptsBeforeUI, IClientScriptManager clientScriptManager, 1819 ref ScriptReferenceBase applicationServicesReference) { 1820 // ClientScriptManager.RegisterClientScriptInclude() does not register multiple scripts 1821 // with the same type and key. We use the url as the key, so multiple scripts with 1822 // the same final url are handled by ClientScriptManager. In ScriptManager, we only 1823 // need to remove ScriptReferences that we consider "the same" but that will generate 1824 // different urls. For example, Name+Assembly+Path and Name+Assembly will generate 1825 // different urls, but we consider them to represent the same script. For this purpose, 1826 // two scripts are considered "the same" iff Name is non-empty, and they have the same 1827 // Name and Assembly. 1828 1829 // This method also removes all the script reference with name equals MicrosoftAjax.js and 1830 // assembly equals System.Web.Extensions when MicrosoftAjax is disabled (MicrosoftAjaxMode == Disabled) 1831 1832 // Scenario: 1833 // Two references from two new instances of the same component that are each in different 1834 // UpdatePanels, during an async post, where one update panel is updating and the other is not. 1835 // If we remove one of the references because we consider one a duplicate of the other, the 1836 // reference remaining may be for the control in the update panel that is not updating, and 1837 // it wouldn't be included (incorrectly). 1838 // So, references from components can only be considered duplicate against static 1839 // script references. The returned list may contain duplicates, but they will be duplicates 1840 // across script controls, which may potentially live in different update panels. 1841 // When rendering the partial update content, duplicate paths are handled and only one is output. 1842 1843 // PERF: Optimize for the following common cases. 1844 // - One ScriptReference (i.e. MicrosoftAjax.js). 1845 // - Two unique ScriptReferences (i.e. MicrosoftAjax.js and MicrosoftAjaxWebForms.js). It is 1846 // unlikely there will be two non-unique ScriptReferences, since the first ScriptReference is always 1847 // MicrosoftAjax.js. 1848 // - Reduced cost from 0.43% to 0.04% in ScriptManager\HelloWorld\Scenario.aspx. 1849 int numScripts = scripts.Count; 1850 if (ajaxFrameworkMode == AjaxFrameworkMode.Enabled) { 1851 if (numScripts == 1) { 1852 ScriptReference script1 = scripts[0] as ScriptReference; 1853 if (script1 != null) { 1854 if (clientScriptManager != null) { 1855 if (!String.IsNullOrEmpty(script1.EffectiveResourceName)) { 1856 RegisterResourceWithClientScriptManager(clientScriptManager, script1.GetAssembly(this), script1.EffectiveResourceName); 1857 } 1858 } 1859 return scripts; 1860 } 1861 } 1862 else if (numScripts == 2) { 1863 ScriptReference script1 = scripts[0] as ScriptReference; 1864 ScriptReference script2 = scripts[1] as ScriptReference; 1865 if ((script1 != null) && (script2 != null) && 1866 ((script1.EffectiveResourceName != script2.EffectiveResourceName) || (script1.Assembly != script2.Assembly))) { 1867 if (clientScriptManager != null) { 1868 if (!String.IsNullOrEmpty(script1.EffectiveResourceName)) { 1869 RegisterResourceWithClientScriptManager(clientScriptManager, script1.GetAssembly(this), script1.EffectiveResourceName); 1870 } 1871 if (!String.IsNullOrEmpty(script2.EffectiveResourceName)) { 1872 RegisterResourceWithClientScriptManager(clientScriptManager, script2.GetAssembly(this), script2.EffectiveResourceName); 1873 } 1874 } 1875 return scripts; 1876 } 1877 } 1878 } 1879 1880 // PERF: HybridDictionary is significantly more performant than Dictionary<K,V>, since the number 1881 // of scripts will frequently be small. Reduced cost from 1.49% to 0.43% in 1882 // ScriptManager\HelloWorld\Scenario.aspx. 1883 HybridDictionary uniqueScriptDict = new HybridDictionary(numScripts); 1884 List<ScriptReferenceBase> filteredScriptList = new List<ScriptReferenceBase>(numScripts); 1885 1886 // CompositeScriptReferences are always included, so scan them first 1887 foreach (ScriptReferenceBase script in scripts) { 1888 var csr = script as CompositeScriptReference; 1889 if (csr != null) { 1890 bool loadBeforeUI = false; 1891 foreach (ScriptReference sr in csr.Scripts) { 1892 // Previously, we weren't removing duplicate path-based scripts 1893 // because the script registration was using the url as the key, 1894 // which resulted in duplicates effectively being removed later. 1895 // With composite script references, this ceases to be true. 1896 Tuple<string, Assembly> key = (String.IsNullOrEmpty(sr.EffectiveResourceName)) ? 1897 new Tuple<string, Assembly>(sr.EffectivePath, null) : 1898 new Tuple<string, Assembly>(sr.EffectiveResourceName, sr.GetAssembly(this)); 1899 if (uniqueScriptDict.Contains(key)) { 1900 // A script reference declared multiple times in one or 1901 // multiple composite script references throws. 1902 throw new InvalidOperationException( 1903 AtlasWeb.ScriptManager_CannotRegisterScriptInMultipleCompositeReferences); 1904 } 1905 else { 1906 if ((clientScriptManager != null) && (key.Item2 != null)) { 1907 // its a resource script, tell ClientScriptManager about it so it suppresses any 1908 // calls to RegisterClientScriptResource 1909 RegisterResourceWithClientScriptManager(clientScriptManager, key.Item2, key.Item1); 1910 } 1911 if ((ajaxFrameworkMode == AjaxFrameworkMode.Explicit) && sr.IsAjaxFrameworkScript(this) && 1912 (applicationServicesReference == null) && 1913 sr.EffectiveResourceName.StartsWith("MicrosoftAjaxApplicationServices.", StringComparison.Ordinal)) { 1914 applicationServicesReference = csr; 1915 } 1916 if (!loadScriptsBeforeUI && !loadBeforeUI && NeedToLoadBeforeUI(sr, ajaxFrameworkMode)) { 1917 csr.AlwaysLoadBeforeUI = true; 1918 loadBeforeUI = true; 1919 } 1920 uniqueScriptDict.Add(key, sr); 1921 } 1922 } 1923 } 1924 } 1925 1926 foreach (ScriptReferenceBase script in scripts) { 1927 var csr = script as CompositeScriptReference; 1928 if (csr != null) { 1929 filteredScriptList.Add(csr); 1930 } 1931 else { 1932 var sr = script as ScriptReference; 1933 if (sr != null) { 1934 Tuple<string, Assembly> key = (String.IsNullOrEmpty(sr.EffectiveResourceName)) ? 1935 new Tuple<string, Assembly>(sr.EffectivePath, null) : 1936 new Tuple<string, Assembly>(sr.EffectiveResourceName, sr.GetAssembly(this)); 1937 // skip over duplicates, and skip over MicrosoftAjax.[debug.].js if the mode is Explicit 1938 if (!((ajaxFrameworkMode == AjaxFrameworkMode.Explicit) && sr.IsAjaxFrameworkScript(this) && 1939 (sr.EffectiveResourceName.StartsWith("MicrosoftAjax.", StringComparison.Ordinal))) && !uniqueScriptDict.Contains(key)) { 1940 if (sr.IsStaticReference) { 1941 // only static script references are compared against for duplicates. 1942 uniqueScriptDict.Add(key, sr); 1943 } 1944 if ((ajaxFrameworkMode == AjaxFrameworkMode.Explicit) && sr.IsAjaxFrameworkScript(this) && 1945 (applicationServicesReference == null) && 1946 sr.EffectiveResourceName.StartsWith("MicrosoftAjaxApplicationServices.", StringComparison.Ordinal)) { 1947 applicationServicesReference = sr; 1948 } 1949 if (!loadScriptsBeforeUI && NeedToLoadBeforeUI(sr, ajaxFrameworkMode)) { 1950 sr.AlwaysLoadBeforeUI = true; 1951 } 1952 if ((clientScriptManager != null) && (key.Item2 != null)) { 1953 // its a resource script, tell ClientScriptManager about it so it suppresses any 1954 // calls to RegisterClientScriptResource 1955 RegisterResourceWithClientScriptManager(clientScriptManager, key.Item2, key.Item1); 1956 } 1957 filteredScriptList.Add(sr); 1958 } 1959 } 1960 } 1961 } 1962 return filteredScriptList; 1963 } 1964 1965 // Internal virtual for testing. Cannot mock static RegisterStartupScript(). RegisterStartupScriptInternal(Control control, Type type, string key, string script, bool addScriptTags)1966 internal virtual void RegisterStartupScriptInternal(Control control, Type type, string key, string script, bool addScriptTags) { 1967 RegisterStartupScript(control, type, key, script, addScriptTags); 1968 } 1969 1970 [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The overload specifically exists to strengthen the support for passing in a Page parameter.")] RegisterStartupScript(Page page, Type type, string key, string script, bool addScriptTags)1971 public static void RegisterStartupScript(Page page, Type type, string key, string script, bool addScriptTags) { 1972 ScriptRegistrationManager.RegisterStartupScript(page, type, key, script, addScriptTags); 1973 } 1974 RegisterStartupScript(Control control, Type type, string key, string script, bool addScriptTags)1975 public static void RegisterStartupScript(Control control, Type type, string key, string script, bool addScriptTags) { 1976 ScriptRegistrationManager.RegisterStartupScript(control, type, key, script, addScriptTags); 1977 } 1978 Render(HtmlTextWriter writer)1979 protected internal override void Render(HtmlTextWriter writer) { 1980 if (!IsInAsyncPostBack && (AjaxFrameworkMode != AjaxFrameworkMode.Disabled)) { 1981 if (!((IControl)this).DesignMode && SupportsPartialRendering) { 1982 PageRequestManager.Render(writer); 1983 } 1984 1985 if (EnableHistory && !DesignMode && (IPage != null)) { 1986 // Render hidden field for the script manager 1987 writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden"); 1988 writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID); 1989 writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID); 1990 writer.RenderBeginTag(HtmlTextWriterTag.Input); 1991 writer.RenderEndTag(); 1992 1993 // Render initialization script 1994 // Dev10 540269: History startup script moved to directly rendered script so that 1995 // (1) is occurs before the iframe is rendered 1996 // (2) after the state hidden field 1997 // A ClientScript block would violate #2, and StartupScript violates #1. 1998 // Navigation handler remains as a StartupScript since the handler may be defined inline within the page. 1999 JavaScriptSerializer serializer = new JavaScriptSerializer(new SimpleTypeResolver()); 2000 writer.Write(ClientScriptManager.ClientScriptStart); 2001 if (IsDebuggingEnabled && (AjaxFrameworkMode == AjaxFrameworkMode.Explicit)) { 2002 writer.WriteLine("Type._checkDependency('MicrosoftAjaxHistory.js', 'ScriptManager.EnableHistory');"); 2003 } 2004 writer.Write("Sys.Application.setServerId("); 2005 writer.Write(serializer.Serialize(ClientID)); 2006 writer.Write(", "); 2007 writer.Write(serializer.Serialize(UniqueID)); 2008 writer.WriteLine(");"); 2009 if ((_initialState != null) && (_initialState.Count != 0)) { 2010 writer.Write("Sys.Application.setServerState('"); 2011 writer.Write(HttpUtility.JavaScriptStringEncode(GetStateString())); 2012 writer.WriteLine("');"); 2013 } 2014 writer.WriteLine("Sys.Application._enableHistoryInScriptManager();"); 2015 writer.Write(ClientScriptManager.ClientScriptEnd); 2016 2017 if (!String.IsNullOrEmpty(ClientNavigateHandler)) { 2018 string script = "Sys.Application.add_navigate(" + ClientNavigateHandler + ");"; 2019 ScriptManager.RegisterStartupScript(this, typeof(ScriptManager), "HistoryNavigate", script, true); 2020 } 2021 2022 HttpBrowserCapabilitiesBase browserCaps = IPage.Request.Browser; 2023 // Generating the iframe on the server-side allows access to its document 2024 // without access denied errors. This enables the title to be updated in history. 2025 // DevDiv 13920: Output the iframe even if it looks like IE8+ since it could be in a lower document mode 2026 if (browserCaps.Browser.Equals("IE", StringComparison.OrdinalIgnoreCase)) { 2027 // DevDivBugs 196735 2028 // Empty page title causes us to name the first server history point after 2029 // the last thing navigated to, which is the url of the frame. That shows some 2030 // garbled characters in the history list in case it contains multibyte chars in IE. 2031 // We never want the page title to be empty. 2032 if (String.IsNullOrEmpty(IPage.Title)) { 2033 IPage.Title = AtlasWeb.ScriptManager_PageUntitled; 2034 } 2035 string iFrameUrl = (EmptyPageUrl.Length == 0) ? 2036 ScriptResourceHandler.GetEmptyPageUrl(IPage.Title) : 2037 EmptyPageUrl + 2038 ((EmptyPageUrl.IndexOf('?') != -1) ? "&title=" : "?title=") + 2039 IPage.Title; 2040 writer.AddAttribute(HtmlTextWriterAttribute.Id, "__historyFrame"); 2041 writer.AddAttribute(HtmlTextWriterAttribute.Src, iFrameUrl); 2042 writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); 2043 writer.RenderBeginTag(HtmlTextWriterTag.Iframe); 2044 writer.RenderEndTag(); 2045 } 2046 } 2047 } 2048 base.Render(writer); 2049 } 2050 SetFocus(Control control)2051 public void SetFocus(Control control) { 2052 PageRequestManager.SetFocus(control); 2053 } 2054 SetPageTitle(string title)2055 private void SetPageTitle(string title) { 2056 if ((Page != null) && (Page.Header != null)) { 2057 Page.Title = title; 2058 } 2059 } 2060 2061 [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "ID")] SetFocus(string clientID)2062 public void SetFocus(string clientID) { 2063 PageRequestManager.SetFocus(clientID); 2064 } 2065 SetStateValue(string key, string value)2066 private void SetStateValue(string key, string value) { 2067 if (value == null) { 2068 if (_initialState.ContainsKey(key)) { 2069 _initialState.Remove(key); 2070 } 2071 } 2072 else { 2073 if (_initialState.ContainsKey(key)) { 2074 _initialState[key] = value; 2075 } 2076 else { 2077 _initialState.Add(key, value); 2078 } 2079 } 2080 } 2081 2082 #region IControl Members 2083 HttpContextBase IControl.Context { 2084 get { 2085 return new System.Web.HttpContextWrapper(Context); 2086 } 2087 } 2088 2089 bool IControl.DesignMode { 2090 get { 2091 return DesignMode; 2092 } 2093 } 2094 #endregion 2095 2096 #region IScriptManagerInternal Members IScriptManagerInternal.RegisterProxy(ScriptManagerProxy proxy)2097 void IScriptManagerInternal.RegisterProxy(ScriptManagerProxy proxy) { 2098 // Under normal circumstances a ScriptManagerProxy will only register once per page lifecycle. 2099 // However, a malicious page developer could trick a proxy into registering more than once, 2100 // and this is guarding against that. 2101 if (!Proxies.Contains(proxy)) { 2102 Proxies.Add(proxy); 2103 } 2104 } 2105 IScriptManagerInternal.RegisterUpdatePanel(UpdatePanel updatePanel)2106 void IScriptManagerInternal.RegisterUpdatePanel(UpdatePanel updatePanel) { 2107 PageRequestManager.RegisterUpdatePanel(updatePanel); 2108 } 2109 IScriptManagerInternal.UnregisterUpdatePanel(UpdatePanel updatePanel)2110 void IScriptManagerInternal.UnregisterUpdatePanel(UpdatePanel updatePanel) { 2111 PageRequestManager.UnregisterUpdatePanel(updatePanel); 2112 } 2113 #endregion 2114 2115 #region IPostBackDataHandler Members IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)2116 bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) { 2117 return LoadPostData(postDataKey, postCollection); 2118 } 2119 IPostBackDataHandler.RaisePostDataChangedEvent()2120 void IPostBackDataHandler.RaisePostDataChangedEvent() { 2121 RaisePostDataChangedEvent(); 2122 } 2123 #endregion 2124 2125 #region IPostBackEventHandler Members IPostBackEventHandler.RaisePostBackEvent(string eventArgument)2126 void IPostBackEventHandler.RaisePostBackEvent(string eventArgument) { 2127 RaisePostBackEvent(eventArgument); 2128 } 2129 #endregion 2130 2131 #region IScriptManager Members IScriptManager.RegisterArrayDeclaration(Control control, string arrayName, string arrayValue)2132 void IScriptManager.RegisterArrayDeclaration(Control control, string arrayName, string arrayValue) { 2133 RegisterArrayDeclaration(control, arrayName, arrayValue); 2134 } 2135 IScriptManager.RegisterClientScriptBlock(Control control, Type type, string key, string script, bool addScriptTags)2136 void IScriptManager.RegisterClientScriptBlock(Control control, Type type, string key, string script, bool addScriptTags) { 2137 RegisterClientScriptBlock(control, type, key, script, addScriptTags); 2138 } 2139 IScriptManager.RegisterClientScriptInclude(Control control, Type type, string key, string url)2140 void IScriptManager.RegisterClientScriptInclude(Control control, Type type, string key, string url) { 2141 RegisterClientScriptInclude(control, type, key, url); 2142 } 2143 IScriptManager.RegisterClientScriptResource(Control control, Type type, string resourceName)2144 void IScriptManager.RegisterClientScriptResource(Control control, Type type, string resourceName) { 2145 RegisterClientScriptResource(control, type, resourceName); 2146 } 2147 IScriptManager.RegisterDispose(Control control, string disposeScript)2148 void IScriptManager.RegisterDispose(Control control, string disposeScript) { 2149 RegisterDispose(control, disposeScript); 2150 } 2151 IScriptManager.RegisterExpandoAttribute(Control control, string controlId, string attributeName, string attributeValue, bool encode)2152 void IScriptManager.RegisterExpandoAttribute(Control control, string controlId, string attributeName, string attributeValue, bool encode) { 2153 RegisterExpandoAttribute(control, controlId, attributeName, attributeValue, encode); 2154 } 2155 IScriptManager.RegisterHiddenField(Control control, string hiddenFieldName, string hiddenFieldValue)2156 void IScriptManager.RegisterHiddenField(Control control, string hiddenFieldName, string hiddenFieldValue) { 2157 RegisterHiddenField(control, hiddenFieldName, hiddenFieldValue); 2158 } 2159 IScriptManager.RegisterOnSubmitStatement(Control control, Type type, string key, string script)2160 void IScriptManager.RegisterOnSubmitStatement(Control control, Type type, string key, string script) { 2161 RegisterOnSubmitStatement(control, type, key, script); 2162 } 2163 IScriptManager.RegisterPostBackControl(Control control)2164 void IScriptManager.RegisterPostBackControl(Control control) { 2165 RegisterPostBackControl(control); 2166 } 2167 IScriptManager.RegisterStartupScript(Control control, Type type, string key, string script, bool addScriptTags)2168 void IScriptManager.RegisterStartupScript(Control control, Type type, string key, string script, bool addScriptTags) { 2169 RegisterStartupScript(control, type, key, script, addScriptTags); 2170 } 2171 IScriptManager.SetFocusInternal(string clientID)2172 void IScriptManager.SetFocusInternal(string clientID) { 2173 PageRequestManager.SetFocusInternal(clientID); 2174 } 2175 2176 bool IScriptManager.IsSecureConnection { 2177 get { 2178 return IsSecureConnection; 2179 } 2180 } 2181 #endregion 2182 2183 // The following class will hijack the page's state persister with its current 2184 // settings so the history server state will be just as safe as the viewstate. 2185 private class StatePersister : PageStatePersister { StatePersister(Page page)2186 public StatePersister(Page page) : base(page) { } 2187 Load()2188 public override void Load() { 2189 throw new NotImplementedException(); 2190 } Save()2191 public override void Save() { 2192 throw new NotImplementedException(); 2193 } 2194 Serialize(object state)2195 public string Serialize(object state) { 2196 return StateFormatter2.Serialize(state, Purpose.WebForms_ScriptManager_HistoryState); 2197 } 2198 Deserialize(string serialized)2199 public object Deserialize(string serialized) { 2200 return StateFormatter2.Deserialize(serialized, Purpose.WebForms_ScriptManager_HistoryState); 2201 } 2202 } 2203 } 2204 } 2205