I'm newbie in asp.net webform. I have so many problems that's almost I got solution from StackOverflow. But Now I'm facing an issue and can't get any desired solution, So, I'm writing this question. I want a textbox to autocomplete with JQuery autocomplete call. I have two textboxes, one is for autocomplete suggestion list, another is getting selected item Id. I don't know how modern website do this. But fortunately, I got a hints by googling it.
Here I have create a codebehind [WebMethod] attribute Method:
Код: Выделить всё
// Class for Custom datatype object public class MyData { public int Id { get; set; } public string Value { get; set; } } // Webmethod for call from ajax [WebMethod] public static MyData GetDataList() { int id = 123; string value = "My Name"; return new MyData { Id = id, Value = value }; }
Код: Выделить всё
$(function () { $("#autocomplete").autocomplete({ source: function (request, response) { $.ajax({ type: 'POST', url: 'reissue_ticket.aspx/GetDataList', data: '{ "term": "' + request.term + '" }', contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (data) { response(data.d); }, error: function () { console.log('Error fetching items.'); } }); }, minLength: 1, select: function (event, ui) { // Set the selected value and id into textboxes $('#selectedValue').val(ui.item.value); $('#selectedId').val(ui.item.id); } }); });
json respose text
Код: Выделить всё
{ "d": { "__type": "eLedger.com.Pages.Services.reissue_ticket+MyData", "Id": 123, "Value": "My Name" } }
Please someone help me to get this problem solve or any better idea with webform.
Thanks in advance for reading my problem at least.
I want the response like {"Id":1, "Value": "My Name"} only.
Источник: https://stackoverflow.com/questions/780 ... om-asp-net