0
votes

I am working on a Visual web part in which I need to list matching data when user type something in text box (like in Google search or Question Title in StackOverflow).

I have ended up in lots of results, but it is for typical c# application. I am looking for a solution which can be implemented directly in my visual web part. I am using SharePoint 2010 and VS 2010.

I did the following things

Installed Ajax Control tool kit. Added the Items to VS toolbox and added the following code snippet.

in .ascx file

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:TextBox ID="txtMovie" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender 
    ID="AutoCompleteExtender1" 
    TargetControlID="txtMovie"  ServiceMethod="GetCompletionList"
    runat="server" UseContextKey="True" />

in .ascx.cs

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]      
public static string GetCompletionList(string prefixText, int count, string contextKey)
{           
    return "Hello";
}

But when I deployed I am getting this error

Only one instance of a ScriptManager can be added to the page.

I removed the <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager> from my .ascx file however after that I am not able to edit my sharepint pages because of some js error.

1
Your question is too broad. What's the source of possible suggestions - a database table, a SharePoint list, a file? What part of this task is a problem for you - retrieving the items from source, showing a list below a textbox?Marek Grzenkowicz
do you want to use web services to gain the data for the auto complete?Truezplaya
The data needs to be fetched from a Database table. I have used Ajax ControlToolkit. But still when I type something in text box nothing happens.aarpey
you can NOT use WebMethod in user control.Arash

1 Answers

0
votes

Not sure why it is not working, came across a codeplex feature that will do the trick for you: http://spautocomplete.codeplex.com/

Also, check out this jQuery solution: http://sharepointwings.blogspot.in/2012/05/autocomplete-textbox-using-jquery-in.html

There is also one available from: Microsoft.Office.Search.WebControls.AutoCompleteExtender regards, KS