Three Patterns of Constructing an ASP.NET AJAX-based Applications - Enable ASP.NET AJAX Support for JSSK
(Page 4 of 4 )
With a general overview of the JSSK's basic function and architecture, we're now ready to supply ASP.NET AJAX support for JSSK. In the following sections, we will apply appropriate controls supplied by ASP.NET AJAX and ASP.NET AJAX Control Toolkit to achieve this goal. First of all, let's enable ASP.NET AJAX Support for JSSK.
Adding the Necessary ASP.NET AJAX Assemblies
This step is pretty easy; you just need to copy the assemblies named Microsoft.Web.Preview.dll and AjaxControlToolkit.dll to the bin folder under the root of the JSSK project. Note here we have not explicitly added the core assembly named Microsoft.Web.Extensions.dll since it was added into the .NET GAC automatically when the MS AJAX framework was initially installed.
Modifying File Web.config
In my opinion, this is the most important and a MUST-HAVE step in ajaxifying the JSSK project. Here we only talk about the associated parts of the sample in this article while omitting the complete configuration for the web.config file in constructing a complex ASP.NET AJAX-based web application.
First of all, to let the HTTP Handler supplied by MS AJAX handle the requests to Web Services and JavaScript resources, you have to add the following configuration code under the <system.web> sub-section of the <configuration> section.
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
<add verb="GET,HEAD,POST" path="*.asbx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
Second, under the <pages> sub-section of the <system.web> section you'd better add the following tag prefixes to register the controls that come from ASP.NET AJAX and ASP.NET AJAX Control Toolkit, a uniform and meaningful prefix.
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagPrefix="asp" namespace="Microsoft.Web.Preview.UI" assembly="Microsoft.Web.Preview"/>
<add tagPrefix="asp" namespace="Microsoft.Web.Preview.UI.Controls" assembly="Microsoft.Web.Preview"/>
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
</controls>
Third, still under the <system.web> section, you must add the following code to create the necessary HTTP Module.
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
Finally, to show the complete exception information during debugging, you'd better set the Mode parameter to Off, which is finished under the <customErrors> sub-section of the <system.web> section.
<customErrors mode="Off" defaultRedirect="customerrorpage.aspx"></customErrors>
A big step to ajaxifying your legacy ASP.NET 2.0 applications has been finished! You can refer to the downloaded source code for detailed info. Let's go on with the more detailed aspects.
Adding the Server Control-ScriptManager
The ScriptManager server-side control serves at the headquarters of each ASP.NET AJAX-based application, which mainly takes the responsibilities of sending the necessary JavaScript files and Web Service proxy in the run time to the client-side browser. Note that since nearly every web page in JSSK needs be enhanced using ASP.NET AJAX, it is suggested that you add the ScriptManager control into the MasterPage.master master page, where you get it done once and forever. There's still one point to note: you have to add this control before all the other ASP.NET AJAX controls, so you can place it next to the <form> section as shown below:
<form id="form1" runat="server" visible="true">
<asp:ScriptManager ID="sm" EnablePartialRendering="true" runat="server" />
Please check back tomorrow for the second part of this three-part article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |