2

and thanks for reading my post..

I have a list which i use for databinding some repaters in my aspx.cs file. I'm now creating a autocomplete functionality where i need to use "AJAX Autocomplete for JQuery" (or simular...) to use this list (or.. atleast "id" and "name").

Issue is that i dont know how i through the aspx.cs file (preferrably a [WebMethod]) can "send" this list to the front-end, and use it for autocompleting.

Here is an example of the implementation...

With AJAX :

$('#autocomplete').autocomplete({
    serviceUrl: '/autocomplete/countries',
    onSelect: function (suggestion) {
        alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
    }
});

Without AJAX :

var countries = [
   { value: 'Andorra', data: 'AD' },
   // ...
   { value: 'Zimbabwe', data: 'ZZ' }
];
$('#autocomplete').autocomplete({
    lookup: countries,
    onSelect: function (suggestion) {
        alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
    }
});

Anyone ?

शेखर
  • 17,412
  • 13
  • 61
  • 117
Terje Nygård
  • 1,233
  • 6
  • 25
  • 48

1 Answers1

0

To handle getting values from javascript to asp.net you would use the JavaScriptSerializer class.

Example: http://atsung.wordpress.com/2008/08/07/javascriptserializer-example/

To handle posting data from asp.net to javascript you can use JSON.

Example: http://www.mikesdotnetting.com/Article/96/Handling-JSON-Arrays-returned-from-ASP.NET-Web-Services-with-jQuery

Vortex
  • 663
  • 6
  • 7