次の方法で共有


Adding ASP.Net AJAX to existing websites

I'm sure this has been posted a thousand times on other blogs, but I thought I'd put it up here anyway.

If you want to add Microsoft ASP.Net AJAX (v1.0 RTM) to an existing website assuming you've installed the RTM edition you can do it by adding some stuff to the web.config file:

Firstly - in the system.web section add the following line:

     <pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </controls>
    </pages>

This will save you having to have the following directive at the top of each page:

 <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

If you find you are getting the nasty "'Sys' is undefined error on your pages, putting the following into the System.Web section will fix this:

     <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"/>
    </httpHandlers>

    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </httpModules>

Thats it!  All you should need to do now is just drop a script manager and update panel on the page and throw the controls you want to AJAX-enable in them and you are locked and loaded.

Technorati tags: ASP.Net, ASP, .Net, Web Development, AJAX, Microsoft, Visual Studio

Comments

  • Anonymous
    February 20, 2007
    Thank you. This is exactly what I need. I have a plain ASP.NET app and I want to add AJAX capabilities piecemeal, but didn't want to create a new AJAX project.

  • Anonymous
    February 20, 2007
    You're welcome :-)

  • Anonymous
    September 21, 2007
    Adding ASP.NET AJAX to Existing Websites

  • Anonymous
    September 21, 2007
    Adding ASP.NET AJAX to Existing Websites