Reputation: 30303
I am using autocomplete extender in my application but it is not working. This is my code:
<form id="form1" runat="server">
<asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div>
<cc1:AutoCompleteExtender TargetControlID="TextBox1" MinimumPrefixLength="1"
ServiceMethod="GetVideoTitles" CompletionSetCount="10" ServicePath="Myservices.asmx" ID="AutoCompleteExtender1" runat="server">
</cc1:AutoCompleteExtender>
</div>
</form>
This is the webservice method:
public string[] GetVideoTitles(string prefixText)
{
SqlConnection con = new SqlConnection(@"Data Source=SERVER5\SQLserver2005;Initial Catalog=tpvnew;User ID=xx;Password=525");
con.Open();
SqlCommand cmd = new SqlCommand("video_videotitles", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@prefixText", SqlDbType.VarChar, 50);
cmd.Parameters["@prefixText"].Value = prefixText;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["videotitle"].ToString(), i);
i++;
}
return items;
}
Upvotes: 0
Views: 1369
Reputation: 2931
you miss this
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = **prefixText + "%"**;
and in your query must use
like @prefixText
Upvotes: 0
Reputation: 2724
Try to see if your web method GetVideoTitles() works or not. if it works, then check if you have set your .asmx web service path in the scriptmanager.
<asp:ScriptManager ID="smMain" runat="server">
<Services>
<asp:ServiceReference Path="~/WebServices/AutoComplete.asmx"/>
</Services>
</asp:ScriptManager>
Upvotes: 0
Reputation: 66641
Try this trick
public string[] GetVideoTitles(string prefixText) {
try
{
...Your code...
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["videotitle"].ToString(), i);
Debug.Write(dr["videotitle"].ToString());
i++;
}
...Your code...
}
catch(Exception)
{
Debug.Assert(false);
}
}
This way you first locate if somthing stop running on webservice method. Also use the DebugView from sysinternals to check live the data you get from Debug.write()
Hope this 2 thinks help you locate the bug.
-- Found this on asp.net forums-- http://forums.asp.net/t/1123944.aspx
In most cases where the WebService method does not get calls becasue the WebMethod Signature does not match with the AutoComplete Extender signature. The Method signature needs to be:
string[] WSMethodName(string prefixText, int count)
You can have different method name but the parameter names and return type needs to be exact match even in case.
Reading this page http://www.vishwamohan.com/post/2007/05/07/AJAX-Error-Sys-is-undefined.aspx
and this page http://blogs.imeta.co.uk/TAxworthy/archive/2009/01/15/569.aspx Found that the sys problem can solve that way....
The most important line was:
allowDefinition="MachineToApplication"
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
When compared to the application’s web.config, the last section was missing. When this line was amended, the javascript error was fixed, and the AJAX controls worked correctly again.
Upvotes: 1
Reputation: 3890
Have you tried setting a breakpoint in your GetVideoTitles method, and verified that it returns any items?
Upvotes: 1