原创:ASP.NET2.0中使用AJAX1.0控件的一点经验

Posted on 2008-03-17 15:06  蓝箭GZ  阅读(440)  评论(0编辑  收藏  举报


 

第一次用ajax.1.0控件,下载安装ASP.NET AJAX1.0后,在VS中建立网站时多了一个选项:ASP.NET AJAX-Enabled Web Site,以及工具栏中多了AJAX Extensions选项,包括有ScriptManager,UpdatePanel等控件,

分两种情况:

第一种情况,新建的网站是通过ASP.NET AJAX-Enabled Web Site而新建的,就比较好办,先放入ScriptManager控件,后放入UpdatePanel控件,再将GridView等需要PostBack才能更新或编辑的控件放入UpdatePanel中,这样就可以简单地实现GridView控件无刷新更新数据的效果了;

第二种情况是,已经新建了网站,但不是通过ASP.NET AJAX-Enabled Web Site这个选项而新建的,这时,加入ScriptManage控件,后放入UpdatePanel控件是会出错的,如:“Sys 未定义”等,这样就要修改网站根目录下的web.config文件,加入如下内容:

1.一定要在<configuration>的后面(规定<configSections>要是它的第一个子项),加入

<configuration>

<!--这是加入支持ajax控件的设置1-->

 <configSections>

    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>

        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />

          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />

          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />

        </sectionGroup>

      </sectionGroup>

    </sectionGroup>

 </configSections>

<!--这是加入支持ajax控件的设置1-->

2.在<page>后面加入:

<!--这是加入支持ajax控件的设置2-->

      <controls>

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

      </controls>

<!--这是加入支持ajax控件的设置2-->

</pages>

3.接上面加入

</pages>

 <!--这是加入支持ajax控件的设置3-->

    <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>

<!--这是加入支持ajax控件的设置3-->

4.最后在</system.web>后面加入

</system.web>

<!--这是加入支持ajax控件的设置4-->

 <system.web.extensions>

    <scripting>

      <webServices>

        <!-- Uncomment this line to customize maxJsonLength and add a custom converter -->

        <!--

      <jsonSerialization maxJsonLength="500">

        <converters>

          <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>

        </converters>

      </jsonSerialization>

      -->

        <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->

        <!--

        <authenticationService enabled="true" requireSSL = "true|false"/>

      -->

        <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved

           and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and

           writeAccessProperties attributes. -->

        <!--

      <profileService enabled="true"

                      readAccessProperties="propertyname1,propertyname2"

                      writeAccessProperties="propertyname1,propertyname2" />

      -->

      </webServices>

      <!--

      <scriptResourceHandler enableCompression="true" enableCaching="true" />

      -->

    </scripting>

 </system.web.extensions>

 <system.webServer>

    <validation validateIntegratedModeConfiguration="false"/>

    <modules>

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

    </modules>

    <handlers>

      <remove name="WebServiceHandlerFactory-Integrated" />

      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"

           type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"

           type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    </handlers>

 </system.webServer>

<!--这是加入支持ajax控件的设置4-->

</configuration>

这样旧的项目也可以支持asp.net ajax1.0的功能了。

Copyright © 2024 蓝箭GZ
Powered by .NET 9.0 on Kubernetes