1

I am using the AutoCompleteExtender from the Ajax Control Toolkit and it is behaving stragely.

My service method is shown here:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] getEJMaps(string prefixText, int count)
{   // method that returns the auto-suggest for the EJMaps positions
    string file_location = HttpContext.Current.Server.MapPath("~") + Utils.Settings.Get("attachments") + "ejmaps\\ejmaps.xml";
    XElement x = XElement.Load(file_location);
    string[] positions = (from p in x.Descendants("position") where p.Value.StartsWith(prefixText) orderby p.Value select p.Value).ToArray();
    if (positions.Count() == 0)
        return new string[] { "No Matching Results" };
    else return positions;
}

And it works fine, if I call it in a test page with the values getEJMaps("00056", 4) I get these results:

00056399
00056717
00056721
00056722
00056900
...

Which is exactly what I want, but when I tie it to a TextBox and type in 00056, I get the results:

56399
24015
24017
56717
56721
...

Which shows two problems:

  1. What the hell happened to my zeroes? ANd how can I get them back?
  2. Where did those "240xx" numbers come from? There aren't even any in the xml document with those values whatsoever!

I am totally baffled by this, please help me out :)

naspinski
  • 34,020
  • 36
  • 111
  • 167

2 Answers2

2

You need to surround each string in the array with quotes. For example, getEJMaps should return an array that looks like:

"00056399"
"00056717"
"00056721"
"00056722"
"00056900"
...

Don't forget you need to escape the quotes with a \

If this fixes the missing 0's but not the phantom values, let me know and I'll try to assist with that as well. I'm thinking it will though.

colithium
  • 10,269
  • 5
  • 42
  • 57
  • they were all strings - that's the strange part; I gave up on the toolkit and went with jQuery instead http://naspinski.net/post/Using-jqueryautosuggestjs-with-AspNet.aspx – naspinski Feb 04 '09 at 06:11
  • Just to make sure I didn't misunderstand your comment. You did try surrounding the strings with quotation marks right? I know 00056399 is a string but from my research, it has to be a string WITH quotes: String mystring = "\"00056399\"" – colithium Feb 04 '09 at 07:54
1
SELECT   
'''' + CustomerShipTo + '''' AS CustomerShipTo   

FROM dbo.CustomerMaster   

This should work..... It worked for me

Dan McClain
  • 11,780
  • 9
  • 47
  • 67