This project is read-only.

Enable AJAX Recipe

The guidance package includes the recipe named Enable Ajax, which allows you to enable a Web site to use ASP.NET AJAX Extensions. After you register (or install) the guidance package, the recipe is available on the Solution Explorer shortcut menu that appears when you right-click the Web site root node. Figure 1 illustrates the recipe menu.
EnableAjaxRecipeMenu.png
Figure 1
The Enable Ajax recipe menu.

Implementation Details

You can find the recipe definition in the EnableWebClientFactoryAjax.xml file (this file is located in the Recipes folder of the WebClientFactoryPackage project).
You use the HostData section in a recipe definition to specify where in the Visual Studio interface the recipe will be shown. In the EnableWebClientFactoryAjax.xml file, two command bars are defined in the HostData section.

<HostData>
  <CommandBar Menu="WCSFWebProject" />
  <CommandBar Menu="WCSFWebApplicationProject" />
</HostData>

The first command bar is associated with the WCSFWebProject menu; the second command bar is associated with the WCSFWebApplicationProject menu.
The WCSFWebProject menu is displayed when the user right-clicks a Web site node in Solution Explorer; the WCSFWebApplicationProject menu is displayed when the user right-clicks a Web Application project node in Solution Explorer.
The WCSFWebProject menu and the WCSFWebApplicationProject menu are defined in the file WebClientFactoryPackage.xml located in the root of the WebClientFactoryPackage project.

<Menu Name="WCSFWebProject" Text="Web Client Factory" Priority="1">
  <CommandBar Name="Web Project"/>
</Menu>
<Menu Name="WCSFWebApplicationProject" Text="Web Client Factory" Priority="1">
  <CommandBar Guid="D309F791-903F-11D0-9EFC-00A0C911004F" ID="1026"/>
</Menu>

The Enable Ajax recipe updates the Web.config file to include the elements required to support Microsoft ASP.NET AJAX. To do this, the actions in the following XML are executed.

<Action Name="GetOrCreateWebconfig" Type="Microsoft.Practices.WebClientFactory.Actions.GetOrCreateProjectItemAction, Microsoft.Practices.WebClientFactory.GuidancePackage">
  <Input Name="Project" RecipeArgument="SelectedWebProject"/>
  <Input Name="ItemName" RecipeArgument="WebConfigFileName"/>
  <Input Name="Template" RecipeArgument="WebConfigPath"/>
  <Output Name="ProjectItem"/>
</Action>
<Action Name="LoadXml" Type="Microsoft.Practices.RecipeFramework.Library.XML.Actions.LoadXmlAction, Microsoft.Practices.RecipeFramework.Library">
  <Input Name="ProjectItem" ActionOutput="GetOrCreateWebconfig.ProjectItem"/>
  <Output Name="XmlDoc"/>
</Action>
<Action Name="EnableAjaxOnWebProject" Type="Microsoft.Practices.WebClientFactory.Actions.EnableAjaxOnWebProjectAction, Microsoft.Practices.WebClientFactory.GuidancePackage">
  <Input Name="Project" RecipeArgument="SelectedWebProject"/>
  <Input Name="XmlDoc" ActionOutput="LoadXml.XmlDoc"/>
</Action>
<Action Name="SaveXml" Type="Microsoft.Practices.RecipeFramework.Library.XML.Actions.SaveXmlAction, Microsoft.Practices.RecipeFramework.Library">
  <Input Name="ProjectItem" ActionOutput="GetOrCreateWebconfig.ProjectItem"/>
  <Input Name="XmlDoc" ActionOutput="LoadXml.XmlDoc"/>
</Action>

Note:
The Enable Ajax recipe performs the steps described in the topic Configuring ASP.NET AJAX. For a detailed description of the steps performed by the recipe, see the section “Adding ASP.NET AJAX Configuration Elements to an Existing Web Site” in the aforementioned topic.

After modifying the content of the Web.config file, the following action adds a reference in the selected project to the System.Web.Extensions.dll assembly.

<!-- Add references to System.Web.Extensions -->
<Action Name="AddExtensionsAssemblyReferenceToWeb" Type="AddAssembliesReferenceAction">
  <Input Name="FileNames" RecipeArgument="WebExtensionsAssembly"/>
  <Input Name="ReferringProject" RecipeArgument="SelectedWebProject"/>
  <Input Name="AssembliesPath" RecipeArgument="WebExtensionsAssemblyPath"/>
</Action>

Enable AJAX Next Steps

EnableAJAXNextSteps.png

Last edited Nov 12, 2007 at 5:08 PM by siacomuzzi, version 2

Comments

No comments yet.