Ajax ScriptManager
The ASP .NET ScriptManager manages ASP.NET Ajax script libraries and script files, partial-page rendering, and client proxy class generation for Web and application services. Here are some tips for the ScriptManager that I have found useful.
Please note that many of these topics apply to ASP .NET 4.0.
Access ScriptManager From Child
You can only have one instance of the ScriptManager per page, so a common practice for a web form application that uses Master Pages is to put that reference in the master page. To access this instance from the child page, you must call the GetCurrent static method and pass in a reference to the page.
ScriptManager sm = ScriptManager.GetCurrent(this);
Access ScriptManager From UserControl
From a user control, you do the same thing, but this time the page reference comes from the Control.Page property.
ScriptManager sm = ScriptManager.GetCurrent(this.Page);
Register Async PostBack Control
To register a control as a trigger for asynchronous postbacks from code, you must first obtain the reference to the ScriptManager, and then call the RegisterAsyncPostBackControl method, passing in your control.
ScriptManager sm = ScriptManager.GetCurrent(this);
sm.RegisterAsyncPostBackControl(btnSave);
ScriptMode Property
The ScriptMode property controls whether debug or release versions of the script libraries are rendered to the browser. You should ONLY use the debug mode in development, as the debug libraries are much larger than the release versions. If no script mode is specified, then debug mode will be used when the retail attribute of the deployment configuration element is set to false. Since this setting cannot be set at the application level (machine level only), setting the script mode to release for deployment is recommended.
asp:ScriptManager ID="SM1" runat="server" ScriptMode="Release"
EnableCdn Property
The EnableCdn property allows you to specify whether the script libraries are loaded from Microsoft’s Content Delivery Network (CDN) or not. Using the CDN is recommended, as it will load the most up to date script libraries from cache servers located around the world, which can significantly improve your website’s performance, and ensure that you are always using the latest libraries.
asp:ScriptManager ID="SM1" runat="server" EnableCdn="true"
Please note that many of these topics apply to ASP .NET 4.0.
Access ScriptManager From Child
You can only have one instance of the ScriptManager per page, so a common practice for a web form application that uses Master Pages is to put that reference in the master page. To access this instance from the child page, you must call the GetCurrent static method and pass in a reference to the page.
ScriptManager sm = ScriptManager.GetCurrent(this);
Access ScriptManager From UserControl
From a user control, you do the same thing, but this time the page reference comes from the Control.Page property.
ScriptManager sm = ScriptManager.GetCurrent(this.Page);
Register Async PostBack Control
To register a control as a trigger for asynchronous postbacks from code, you must first obtain the reference to the ScriptManager, and then call the RegisterAsyncPostBackControl method, passing in your control.
ScriptManager sm = ScriptManager.GetCurrent(this);
sm.RegisterAsyncPostBackControl(btnSave);
ScriptMode Property
The ScriptMode property controls whether debug or release versions of the script libraries are rendered to the browser. You should ONLY use the debug mode in development, as the debug libraries are much larger than the release versions. If no script mode is specified, then debug mode will be used when the retail attribute of the deployment configuration element is set to false. Since this setting cannot be set at the application level (machine level only), setting the script mode to release for deployment is recommended.
asp:ScriptManager ID="SM1" runat="server" ScriptMode="Release"
EnableCdn Property
The EnableCdn property allows you to specify whether the script libraries are loaded from Microsoft’s Content Delivery Network (CDN) or not. Using the CDN is recommended, as it will load the most up to date script libraries from cache servers located around the world, which can significantly improve your website’s performance, and ensure that you are always using the latest libraries.
asp:ScriptManager ID="SM1" runat="server" EnableCdn="true"
0 comments:
Post a Comment