Deploying Client Files


The recommended approach for incorporating client-side behavior into your controls is to create a script library or a set of files that are referenced by the HTML that your control renders , rather than rendering the client script your control needs directly into the page. There are a number of benefits associated with this approach:

  • Because your controls emit only references to script files, this technique reduces the size of the rendered pages.

  • Web browsers can cache your script files for use across various pages. This improves the overall performance of a Web application.

  • You can support multiple instances of the same control within the same page more easily. Each instance uses the same script reference, as opposed to rendering slight variations (based on the ID of the control) of the same script functionality into the page.

  • Packaging the script outside the code for your control allows you to maintain and modify the script much more easily, without having to recompile your control.

ASP.NET provides a shared location that is a common directory and virtual root to be used for all client files. This shared location allows the client files to be reused across multiple applications. It also allows page developers to use controls without having to copy the client files associated with them into every application they use a control in. This capability is particularly important for controls that are installed into the global assembly cache (GAC) for use across multiple applications. Because the GAC supports side-by-side installation of multiple versions of your control, this shared location is associated with a deployment scheme that enables multiple versions of your client script files to coexist.

For example, the validation controls in ASP.NET deploy their client file, WebUIValidation.js, in this shared location. On a machine that has Internet Information Services (IIS) installed at c:\inetpub\ wwwroot , WebUIValidation.js is installed as the following:

 c:\inetpub\wwwroot\aspnet_client\system_web_0_3705_0\ WebUIValidation.js 

WebUIValidation.js is referenced by using a root-relative URL:

 /aspnet_client/system_web/1_0_3705_0/WebUIValidation.js 

When the .NET Framework is installed, the "aspnet_client" directory is created and registered as the IIS virtual root "aspnet_client." ASP.NET also creates the "system_web" and "1_0_3705_0" subdirectories, which correspond to the System.Web assembly whose version number is 1.0.3705.0.

If you provide an installation program along with your control, it should create a folder with the same name as your control's assembly. This isolates your client files from other controls installed on the same machine. Your control's installation program should also create a subfolder based on your assembly's version. This allows a number of versions of your control to coexist. Your control is then free to implement any directory structure underneath the version folder. We'll show you how to create references to these files from your control in the next section, where we examine the HtmlEditor control. If you do not provide an installation program, you should provide alternate instructions for the page developer to create the necessary directory structure manually.

The files that you can include in this library of client files are not limited to script files. You can also package any other files that your control might need, such as image files and style sheets.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net