2009-08-11 36 views
1

我一直在尝试使用ASP.NET Ajax控件工具包中的AutoComplete Extender,但是我一直有很多麻烦让它实际工作。ASP.Net:元素<name>不是已知元素

要安装AjaxControlToolKit,我将它放在我的应用程序的bin direct中,然后我将它拖放到窗体中。然而,它口口声声说,

“元素‘AutoCompleteExtender’是未知元素”

所以刚开始,我以为我也没有登记过,但当时我看了看标题,它已经在那里:

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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"%> 

所以我不确定,为什么它仍然给我的问题。在我的bin文件夹

其他组件文件包括:

System.Web.Extensions.ddl System.Web.Extensions.Design.dll

这里是我的代码:

<asp:TextBox ID="txtOrganization" runat="server" Width ="500px" MaxLength ="250"></asp:TextBox> 
<asp:ScriptManager ID="ScriptManager1" runat="server"> 
    <Services> 
     <asp:ServiceReference Path="AutoComplete.asmx" /> 
    </Services> 
</asp:ScriptManager> 
<ajaxToolkit:AutoCompleteExtender runat="server" TargetControlID="txtOrganization" ServiceMethod="GetOrganizationList" ServicePath="AutoComplete.asmx"></ajaxToolkit:AutoCompleteExtender> 

回答

1

我修复了它并使其工作。我不得不改变我的aspx页面和我的web.config。

ASPX: 将此添加到我的网页的顶部:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"%> 

我现在的控制是这样的:

 <asp:TextBox ID="txtOrganization" runat="server" Width ="500px" MaxLength ="250"></asp:TextBox> 
     <asp:ScriptManager ID="ScriptManager1" runat="server" > 
      <Services> 
       <asp:ServiceReference Path="AutoComplete.asmx" /> 
      </Services> 
     </asp:ScriptManager> 
     <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoComplete1" 
              TargetControlID="txtOrganization" 
              ServicePath="AutoComplete.asmx" ServiceMethod="GetOrganizationList" 
              MinimumPrefixLength="1" EnableCaching="true" 
              FirstRowSelected="true"> 
     </ajaxToolkit:AutoCompleteExtender> 

至于我的web.config,我增加了以下内容:

<configSections> 
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> 
     <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> 
      <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/> 
      <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> 
       <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/> 
       <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/> 
      </sectionGroup> 
     </sectionGroup> 
    </sectionGroup> 
</configSections> 

<system.web> 
    <pages> 
     <controls> 
      <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
     </controls> 
    </pages> 
    <customErrors mode="Off"/> 
    <compilation debug="true" strict="false" explicit="true"> 
     <assemblies> 
      <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
      <add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> 
      <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
     </assemblies>    
    </compilation> 
    <httpHandlers> 
     <remove verb="*" path="*.asmx"/> 
     <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
     <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
     <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/> 
    </httpHandlers> 
    <httpModules> 
     <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    </httpModules> 
    <sessionState mode="InProc" cookieless="false" timeout="240"/> 
    <!-- 
     The <authentication> section enables configuration 
     of the security authentication mode used by 
     ASP.NET to identify an incoming user. 
    --> 
    <authentication mode="Forms"/> 
    <!-- 
     The <customErrors> section enables configuration 
     of what to do if/when an unhandled error occurs 
     during the execution of a request. Specifically, 
     it enables developers to configure html error pages 
     to be displayed in place of a error stack trace. 

    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> 
     <error statusCode="403" redirect="NoAccess.htm" /> 
     <error statusCode="404" redirect="FileNotFound.htm" /> 
    </customErrors> 
    --> 
    <httpRuntime maxRequestLength="16000" useFullyQualifiedRedirectUrl="true" executionTimeout="180"/> 
</system.web> 
<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=3.5.0.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=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
     <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.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=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    </handlers> 
</system.webServer> 

最初,因为我使用的是asp.net 2.0,System.Web.Extensions的版本号是1.6 ....所以我必须将它全部更改为3.5.0.0。

此外,当搜索解决方案时,很多人说我必须将System.Web.Extensions.dll和System.Web.Extensions.Design.dll的副本放入bin文件夹中。我不必这样做,我只是添加了对他们的引用。

0

难道你为项目添加一个引用吗? 右键点击Visual Studio中的项目...点击属性 在引用旁边,您应该看到那里的AjaxControlToolkit ... 如果没有,点击添加...进入浏览选项卡并选择它。

我认为没有其他控件的工作?

+0

之前已经添加了对AjaxControlToolKit的引用,但它仍然向我提供了该错误消息。 所有的控制工作,除了AJAX控件工具包和AJAX扩展 – Anton 2009-08-11 20:59:55

0

您是否在页面顶部放置了ScriptManager?您必须这样做才能让Toolkit控件正常工作。

编辑:这个问题有很多潜在的原因;您没有正确安装AJAX工具包,网站中存在编译错误等。更常见的问题之一是您需要在web.config文件中声明工具包。在页面标签内添加以下内容:

<controls> 
<add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/> 
</controls> 
+0

不幸的是,当我添加它,它给了我同样的错误,但是对于ScriptManager的 – Anton 2009-08-11 21:37:42

+0

多挖后,我认为这个问题是别的东西: 命名空间或在项目级别中指定的类型Imports'System.Web.Extensions.Design'不包含任何公共成员或无法找到。确保命名空间或类型已定义并且至少包含一个公共成员。确保导入的元素名称不使用任何别名。 – Anton 2009-08-12 13:33:21

相关问题