views:

6

answers:

0

I have an issue with my webpage which although relatively small needs to be fixed asap. The user can search accounts on the page in either of 2 boxes - a simple ID search, or a text autocompleteextneder. When either of the fields are searched, the page posts back and displays the customers details.

I have an issue where that if they enter an incorrect value in the autocompleteextender field when a record is already displayed, the page simply refreshes and doesn't display any error. I'm guessing that because no ID's are returned from the extender, the ID stays the same as the current one so the page assumes it's just been refreshed.

I need a way to reset the value if a user searches for an incorrect value. I did try resetting it when the user clicks Search, but then even valid searches are wiped.

Here's my web service:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace CustomerMaintenanceProj
{
    /// <summary>
    /// Summary description for AutoComplete1Svc
    /// </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 AutoComplete1Svc : System.Web.Services.WebService
    {

        [WebMethod]

        public string[] GetAutoComplete(string prefixText, int count)
        {
            string connection = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
            string sql = "SELECT * FROM SageAccount WHERE Name LIKE @prefixText AND Customer = 1 AND SageID IS NOT NULL";
            SqlDataAdapter da = new SqlDataAdapter(sql, connection);
            da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
            DataTable dt = new DataTable();
            da.Fill(dt);
            List<string> Names = new List<string>();
            foreach (DataRow dr in dt.Rows)
            {
                Names.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["Name"].ToString() + " (" + dr["SageID"].ToString() + ")", dr["ID"].ToString()));
            }

            return Names.ToArray();

        }
    }
}

And on my page I have the following JS in the head:

function autoCompleteItemSelected(source, eventArgs) {
    var assocHiddenField = document.getElementById(source.get_id() + '_hidden');
    assocHiddenField.value = eventArgs.get_value();
}

This is to populate a field called txtName_hidden with the ID of the record.

Any ideas guys? Thanks