Friday, 25 February 2011

How to resolve error Assembly 'AjaxControlToolkit has a higher version than System.Web.Extensions, Version=1.0.61025.0 referenced assembly


Error 1 Assembly 'AjaxControlToolkit, Version=3.5.40412.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' uses 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'


This error occurs when there is mismatch in AJAXControlToolkit version and System.Web.extensions version.
You can resolve this error without upgrading your System.web.extensions version bu following simple steps.

  1. In Solution Explorer Click and Open Web.config file
  2. Replace this Web.config file with this new Web.config  file .
  3. <?xml version="1.0"?>
  4. <configuration>
  5.   <configSections>
  6.     <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
  7.       <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
  8.         <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
  9.         <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
  10.           <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
  11.           <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
  12.           <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
  13.         </sectionGroup>
  14.       </sectionGroup>
  15.     </sectionGroup>
  16.   </configSections>
  17.   <system.web>
  18.     <pages>
  19.       <controls>
  20.         <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  21.       </controls>
  22.     </pages>
  23.     <!--
  24.           Set compilation debug="true" to insert debugging
  25.           symbols into the compiled page. Because this
  26.           affects performance, set this value to true only
  27.           during development.
  28.     -->
  29.     <compilation debug="true">
  30.       <assemblies>
  31.         <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  32.         <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
  33.         <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  34.         <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  35.       </assemblies>
  36.     </compilation>
  37.     <httpHandlers>
  38.       <remove verb="*" path="*.asmx"/>
  39.       <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  40.       <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"/>
  41.       <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"/>
  42.     </httpHandlers>
  43.     <httpModules>
  44.       <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  45.     </httpModules>
  46.   </system.web>
  47.   <runtime>
  48.     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  49.       <dependentAssembly>
  50.         <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
  51.         <bindingRedirect oldVersion="1.0.61025.0" newVersion="3.5.0.0"/>
  52.       </dependentAssembly>
  53.       <dependentAssembly>
  54.         <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
  55.         <bindingRedirect oldVersion="2.0.0.0" newVersion="3.5.0.0"/>
  56.       </dependentAssembly>
  57.     </assemblyBinding>
  58.   </runtime>
  59.   <system.web.extensions>
  60.     <scripting>
  61.       <webServices>
  62.         <!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
  63.         <!--
  64.       <jsonSerialization maxJsonLength="500">
  65.         <converters>
  66.           <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
  67.         </converters>
  68.       </jsonSerialization>
  69.       -->
  70.         <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
  71.         <!--
  72.         <authenticationService enabled="true" requireSSL = "true|false"/>
  73.       -->
  74.         <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
  75.            and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and
  76.            writeAccessProperties attributes. -->
  77.         <!--
  78.       <profileService enabled="true"
  79.                       readAccessProperties="propertyname1,propertyname2"
  80.                       writeAccessProperties="propertyname1,propertyname2" />
  81.       -->
  82.       </webServices>
  83.       <!--
  84.       <scriptResourceHandler enableCompression="true" enableCaching="true" />
  85.       -->
  86.     </scripting>
  87.   </system.web.extensions>
  88.   <system.webServer>
  89.     <validation validateIntegratedModeConfiguration="false"/>
  90.     <modules>
  91.       <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  92.     </modules>
  93.     <handlers>
  94.       <remove name="WebServiceHandlerFactory-Integrated"/>
  95.       <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"/>
  96.       <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"/>
  97.       <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"/>
  98.     </handlers>
  99.   </system.webServer>
  100. </configuration>
  101. Copy the above code in Web.config file save it debug and run .


Getting Started AJAX control toolkit on vs 2005


  1. Install AJAX web extension 1.0 .you can find it at following link 
  2. AJAXWebExtension1.0
  3. Download AJAX control toolkit from following link:
  4. http://ajaxcontroltoolkit.codeplex.com/releases/view/43475
  5. Extract the downloaded zip file.
  6. Open Visual studio.
  7. Go to toolbox and add a new Item following is pictorial description

Name the new Tab AJAX Control Toolkit it would be added in toolbox like this:
Right click on AJAX Control toolkit and select choose Items. A new dialog box open  give path of file named AjaxControlToolkit.dll (this file is in  AjaxControlToolkit.Binary.NET35.zip).



NOW AJAX control toolkit is installed and ready to use.

AJAX Toolkit Watermark extender example

AJAX  Toolkit provides a variety of controls and extenders.
In this blog  I would discuss use of Watermarkextender to
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"%>

  2. <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
  3. <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </cc1:ToolkitScriptManager>

  4. <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />

  5. <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1"  TargetControlID="TextBox2" WatermarkText="Enter username here" runat="server">
  6. </cc1:TextBoxWatermarkExtender>
Above code is example of  TextBoxWatermarkExtender .

    It has two important properties "TargetControlID" and "WatermarkText"
    TargetControlID: tells to which control this extender is attached.
    WatermarkText: tells the text which would be displayed in target control attached with TextBoxWatermarkExtender.
    Note When you are using  ajax toolkit controls always use ToolkitScriptManager instead of ScriptManager.