asp.net自动完成控件在用户控件上失效的解决方法

Ajax toolkit里的自动完成控件放在一个test.aspx页面,ServiceMethod属性里的方法写在test.aspx.cs页面,此时运行test.aspx页面,AutoCompleteExtender工作正常。

由 于test.aspx里的AutoCompleteExtender功能很多地方都用得到,因此把自动完成部分抽取出来,放到一个用户控件里 test.ascx里,ServiceMethod属性里的方法写在test.ascx.cs里,然后把test.ascx控件拖放到 index.aspx页面里,运行,发现自动完成控件并没有工作!

原因:把AutoCompleteExtender移动到用户控件,然后再在一个aspx页面里使用此控件,ServiceMethod属性里的方法找不到!

解决方法:添加一个独立的test.asmx服务页面,然后在App_Code的test.cs里面实现AutoCompleteExtender的ServiceMethod属性里的方法,最后在用户控件那里调用如下:


<cc1:AutoCompleteExtender ID="aceCropName" runat="server" ServiceMethod="TestServiceMethod"  ServicePath="test.asmx" TargetControlID="txtCrop" FirstRowSelected="true" MinimumPrefixLength="2" />
原文地址:https://www.cnblogs.com/shihao/p/2045565.html