AutoComplete Extender in Master Page
I went through lots of forums, posts etc. But never found really good answer on this. I'm trying to add AutoComplete Extender to TextBox and display some tips to users. Everything is fine when this code is placed in Content Page. But I've got like ~10 Content Pages based on one Master Page so it's completely stup开发者_Python百科id to repeat the code on each one.
There are some answers on the web but they are only partial ones, check if you wan't:
Could post only one link :/
Here is my code:
Master Page:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/AutoComplete.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox runat="server" ID="TextBox1"></asp:TextBox>
<ajax:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="TextBox1"
ServiceMethod="GetCompletionList"
ServicePath="~/AutoComplete.asmx"
MinimumPrefixLength="1"
CompletionInterval="500"
CompletionSetCount="2">
</ajax:AutoCompleteExtender>
WebService:
/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText, int count)
{
// Create array of movies
string[] movies = { "Star Wars", "Star Trek", "Superman", "Memento", "Shrek", "Shrek II" };
// Return matching movies
return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}
}
For the record, I've checked the Web Service and it's working just fine
p.s. It's my firs post so sorry if I've done something wrong
Faced the Similar problem but the only solution that seems to be is writing the Webmethod in the content page itself and the autocompleteextender with its respective controls can be kept at masterpage.
精彩评论