Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi..
I am a beginner to ASP.NET, I am using Visual Studio 2019, (not core, not MVC) and I am coding in VB as I feel comfortable with it. I recently installed AJAX Control Tool Kit v. 19.1. In Webform1.aspx I added a textbox with Autocomplete Extender to get data from a local DB. I also added Scriptmanager ajax tool. But I get this error when running it in web browsers:
AjaxControlToolkit.AutoCompleteExtender missing required ServiceMethod property value for TextBox1_AutoCompleteExtender. Parameter name: ServiceMethod.
I tried many tutorials but they are mostly old and are not supported by VS 2019 anymore.
I would appreciate your help. Below is the ASPX and ASPX.VB codes:

This is Webform1.aspx code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="AutoComplete.WebForm1" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
ScriptPath="AutoComplete.asmx"
TargetControlID="TextBox1" CompletionInterval="12" ServiceMethod="GetCompletionList"



<title>




<asp:scriptmanager id="ScriptManager1" runat="server">


<asp:textbox id="TextBox1" runat="server" height="18px" width="251px">
<ajaxtoolkit:autocompleteextender id="TextBox1_AutoCompleteExtender" runat="server" behaviorid="TextBox1_AutoCompleteExtender" delimitercharacters="" servicepath="" targetcontrolid="TextBox1">






What I have tried:

This is Webform.aspx.VB
Imports System.Data.SqlClient

Public Class WebForm1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

<system.web.services.webmethod()>
<system.web.script.services.scriptmethod()>
Public Shared Function GetUserName(prefixUser As String) As String()
Dim Users As New List(Of String)()
Dim ConStr As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Administrator\source\repos\AutoComplete\AutoComplete\App_Data\Database1.mdf;Integrated Security=True"
Using conn As New SqlConnection(ConStr)
Using cmd As New SqlCommand("select UserName from Userdetails where UserName like '%' + @Textbox1")

cmd.Parameters.AddWithValue("@Textbox1", prefixUser)
cmd.Connection = conn
conn.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
Users.Add(sdr("UserName").ToString())
End While
End Using

conn.Close()
End Using
End Using

Return Users.ToArray()
End Function
End Class
Posted
Updated 19-Jun-20 21:16pm

The error message is perfectly clear: you haven't set the ServiceMethod property on the AutoCompleteExtender.

You need to set it to the name of the service method you want to call - in this case, GetUserName.
 
Share this answer
 
Hi,
I'm using this code for autocomplete
here it is not firing the service method


Admin/PatientAuto1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PatientAuto1.aspx.cs" Inherits="Admin_PatientAuto1" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp"%>

<!DOCTYPE html>



<title>




<asp:scriptmanager id="ScriptManager1" runat="server" enablepagemethods="true">

<asp:autocompleteextender enabled="true" servicemethod="GetSearch" minimumprefixlength="4" completioninterval="10"
="" enablecaching="true" completionsetcount="10" targetcontrolid="TextBox1" id="AutoCompleteExtender1" runat="server" firstrowselected="false">
<asp:label id="Label1" runat="server" text="Search Name">
<asp:textbox id="TextBox1" runat="server">






Admin/PatientAuto1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;


public partial class Admin_PatientAuto1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod]
public static List<string> GetSearch(string term)
{
List<string> listPatientNames = new List<string>();

string cs = ConfigurationManager.ConnectionStrings["CredenceDBConn"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("[dbo].[spGetPatientNames_Vamsi]", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter()
{
ParameterName = "@term",
Value = term
});
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
listPatientNames.Add(rdr["PatientName"].ToString());
}
}

return listPatientNames;
}
}
 
Share this answer
 
Comments
CHill60 22-Jun-20 4:34am    
If you have a question then use the red "Ask a Question" link at the top of this page. Do not post questions or comments as solutions to other members' posts.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900