Bonjour je cherche a réaliser de l'auto complétion dans un textbox a l'aide du composant Ajax AutoCompleteExtender, mais je n'arrive pas à le faire fonctionner
J'ai réaliser le web service me permettant de collecter le tableau de string afficher pour la complétion.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data.SqlClient; using System.Configuration; namespace ecranspecif.Reclamations { /// <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 { string strConnection = ConfigurationManager.ConnectionStrings ["pradoConnectionString"].ConnectionString; // *************************************************************************** // Méthodes d'autocomplétion pour les entreprises // *************************************************************************** [WebMethod] public string[] GetSocByCompletion(string prefixtext, int count) { SqlConnection conn = new SqlConnection(strConnection); conn.Open(); SqlCommand comm = new SqlCommand("SELECT TOP 10 SOC_RAISON FROM TD_SOCIETE WHERE SOC_RAISON LIKE @prefixText", conn); comm.Parameters.AddWithValue("@prefixText", prefixtext + "%"); SqlDataReader dr = comm.ExecuteReader(); List<string> l = new List<string>(); while (dr.Read()) { l.Add(dr["SOC_RAISON"].ToString()); } conn.Close(); string[] t = l.ToArray(); return t; } } }
Et voici le code de ma page avec le composant qui qui utilise la méthode de mon web service.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ecranspecif.Reclamations.Default" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager3" runat="server" /> <div> <asp:TextBox ID="TextBox2" runat="server" style="margin-left: 10px"></asp:TextBox> <cc1:AutoCompleteExtender ID="TextBox2_AutoCompleteExtender" runat="server" CompletionSetCount="10" DelimiterCharacters="" Enabled="True" MinimumPrefixLength="2" ServiceMethod="GetSocByCompletion" ServicePath="~AutoComplete.asmx" TargetControlID="TextBox2"> </cc1:AutoCompleteExtender> </div> </form> </body> </html>
PS: J'ai d'autres composants Ajax sur ma page qui fonctionnent sans problème avec d'autres méthodes du web service tels que des cascadingdropdownlist.J'ai isolé ici dans une nouvelle page mon control pour gagner en clarté.
Je n'ai pas d'erreur retournée mais rien ne se pense lorsque je renseigne le textbox.En mode debug ma methode "GetSocByCompletion" n'est jamais appelée.
J'ai aussi testé cette méthode "GetSocByCompletion" seule elle fonctionne correctement.
Y'a surement quelque chose qui m'échappe, j'ai parcouru les divers tutos sur se site mais je n'ai pas trouvé mon erreur.
Si vous pouvez m'éclairer merci.
Cordialement,
Yann.
Partager