views:

2894

answers:

3

This is c# .net 2.0. I am using a masterpage.

  • The WebService works fine on its own.
  • I am completely stumped. When I type in the TextBox, nothing happens.

Files:

EditTicket.aspx AutoComplete.asmx App_Code/AutoComplete.cs

EditTicket.aspx:

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


        <asp:ScriptManager id="ScriptManager1" runat="server" EnablepageMethods="true">
        <Services>
            <asp:ServiceReference Path="AutoComplete.asmx" />
        </Services>
        </asp:ScriptManager>

    <cc2:AutoCompleteExtender
         runat="server" 
         ID="AutoCompleteExtender1" 
         ServicePath="AutoComplete.asmx" 
         ServiceMethod="AutoComplete2" 
         MinimumPrefixLength="1" 
         CompletionSetCount="12" 
         TargetControlID="TextBox3" 
         EnableCaching="True" >
     </cc2:AutoCompleteExtender>

<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

AutoComplete.asmx:

<%@ WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %>

AutoComplete.cs:

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;


/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class AutoComplete : System.Web.Services.WebService {

    public AutoComplete () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    [ScriptMethod]
    public string[] AutoComplete2(string prefixText,int count)
    {
        string conString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
        SqlConnection connection = new SqlConnection(conString);
        connection.Open();
        SqlParameter prm;
        string sql = "Select program_name FROM CM_Programs WHERE program_name LIKE @prefixText";
        SqlDataAdapter cmd = new SqlDataAdapter(sql, connection);
        prm = new SqlParameter("@prefixText", SqlDbType.VarChar, 50);
        prm.Value = prefixText+ "%";
        cmd.SelectCommand.Parameters.Add(prm);
        DataTable dt = new DataTable();
        cmd.Fill(dt);
        string[] items = new string[dt.Rows.Count];
        int i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            items.SetValue(dr["program_name"].ToString(),i);
            i++;
        }
        connection.Close();
        return items;
    } 
}
+1  A: 

"Nothing happens" is not an easy description to go on. When you say nothing happens, have you checked that

  • The server code is being hit for the web service?
  • Your query is being executed and returning results?
  • Your items array is being populated correctly?

If "nothing" is that none of the above is happening, I would start checking that there are no javascript errors on the page and that your AutoComplete extender is rendering correctly (examine the page controls in a trace).

womp
I was able to run the webservice by itself and get the results of my autocomplete in an array like i expected. That part worked fine. What it finally ended up being was that my website wasn't an AJAX website to begin with, so I had to copy the web.config of an AJAX site and merge with my web.config.
somacore
Can you post explicitly what you changed in web.config because I'm havng the same kind of problem?
Izabela
ok it works for me now. My solution was just not ignoring this phrase in the web service// To allow this Web Service to be called from script, using //ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService()]
Izabela
+1  A: 

Hi somacore,

Try fiddling with the CompletionInterval property. I have used this control in the past and wasn't seeing the behavior I expected until I set the CompletionInterval to a much lower value. It defaults to 1000 (ms), I would give it a shot with a value of 1, just to see if everything is working as it should (and womp's steps should help to narrow down where the communication issues are happening) and if it does work, keep increasing the value until you hit a value that makes sense (1 ms sends a lot of requests to the server). Report back on what works and what doesn't.

AdamB
thanks for the help. I got it figured out (see comment above) but the completion interval definitely needs to be lowered form the default so the user doesn't have to sit and wait for results to appear. Thanks!
somacore
A: 

Hi

even i faced the same issue. The web service was working fine and returning the correct values. At last the issue was i had a breakpoint on the web method . when i removed the breakpoint and tested it. it was working fine :) This might look silly but its true.

Jebli