开发者

AutocompleteExtender not working in master page

I have a problem regarding the autocomplete extender in ASP.NET - it works fine in all pages I have, but NOT in a master page and i don't know why.

Here is my code:

<asp:TextBox runat="server" ID="txtSearch" Width="200px" CssClass="TextBoxClass"></asp:TextBox>
<cc1:AutoCompleteExtender ID="txtSearch_AutoCompleteExtender" runat="server" 
    TargetControlID="txtSearch"
    CompletionInterval="0" 
    CompletionListCssClass="autocomplete_completionListElement"
    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" 
    CompletionListItemCssClass="autocomplete_listItem"
    CompletionSetCount="10" EnableCaching="true" MinimumPrefixLength="2" 
    ServiceMethod="GetCompletionListOggetti"
    ShowOnlyCurrentWordInCompletionListItem="true" UseContextKey="True">
</cc1:AutoCompleteExtender>

Code behind:

<System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()> _
Public Shared Function GetCompletionListOggetti(ByVal prefixText As String, ByVal count As Integer) As String()
    ' Insert code to return a string array here…
    Return AutoCompleteOggetti(prefixTex开发者_StackOverflow中文版t)
End Function

The problem is that GetCompletionListOggetti is never called.

I repeat - it works fine on content page! Thanks in advance.


You need to set the ServicePath property of the AutoCompleteExtender to override the default behaviour of calling back to the loading (not master) page.

Add your function to the code-behind of a webservice page (.asmx), a dummy page, or default.aspx etc.

If using a webservice page, you would need to add/uncomment the line:

<System.Web.Script.Services.ScriptService()> _

for VB, or for C#

[System.Web.Script.Services.ScriptService]


I managed it by putting the web method (in your case, GetCompletionListOggetti) in the code behind file of the content page instead of master page. And it works only for web method in the same code behind file not in a separate asmx service. For this, don't forget to add EnablePageMethods="true" property to your script manager too.

It seems like AutoCompleteExtender's service method is never called when it's defined inside a user(or custom) control's code behind file and a master page is a kind of control indeed.

The downside of this fix is that you have to put the same service method in EVERY contents page which uses this master page. Not very elegant. Another downside is somehow the css of suggestion dropdownlist is not working properly. Still I couldn't figure out the walkaround. Anybody better idea?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜