This article is used for web services using jquery

Here I used the jquery and web service .asmx file. It is very easy to write the code for web service using jquery. We have to write couple of line of code in jquery. I have write the getRefferingPhysicians_jquery web service function which get the date from the database. The “escape” in autocomplete function is use to by pass the single quote. The “UrlDecode” is use in getRefferingPhysicians_jquery function is used for replace single quotation with double quotation in webservice.

The JqueryAutocomplete.aspx code

The jquery file

The java script function for aspx page.

$(function() {
source: function(request, response) {
url: "../Includes/WebServiceRefferingPhysicians.asmx/getRefferingPhysicians_jquery",
data: "{ prefixText:'"+ escape($(".autoRefPhy").val()) +"',count : '10' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function(data) { return data; },
success: function(data) {
response($.map(data, function(item) {
return {
value: item
error: function(XMLHttpRequest, textStatus, errorThrown) {
minLength: 0

The Aspx page control
The div tage is :
div style="height:200px;overflow-y:auto;"

Place input control inside above dive tag :
input type="text" class="autoRefPhy" name="q" id="query" class="ui-autocomplete-input"

The web service .asmx file code is

the code of WebServiceRefferingPhysicians.cs file is. The "getRefferingPhysicians_jquery" javascript file is used in JqueryAutocomplete.

[WebMethod(EnableSession = true)]
public List getRefferingPhysicians_jquery(string prefixText, int count)
string textField, valueField;
string EncounterPhyId = Convert.ToString(Session["EncounterPhyId"]);

string _wherePhyClause = _objCConsultation.CreatePhysicianWhereClause((int)InSync.DataAccess.Enumeration.ResourceType.ReferringPhysician, (int)InSync.DataAccess.Enumeration.ResourceType.Other_Physician, (int)InSync.DataAccess.Enumeration.ResourceType.Physician, (int)InSync.DataAccess.Enumeration.ResourceType.PCP, Session["PracticeId"].ToString(), EncounterPhyId);

if (_wherePhyClause.Length > 0)
_wherePhyClause += " AND ( name like '%" + HttpUtility.UrlDecode(prefixText).Replace("'", "''") + "%' )";
_wherePhyClause = " ( name like '%" + HttpUtility.UrlDecode(prefixText).Replace("'", "''") + "%' )";

DataTable dtResNameLst = _objCConsultation.GetResourceNameAsDataTable(_wherePhyClause, out textField, out valueField);
List lst = new List();
string str = "";
for (int i = 0; i < dtResNameLst.Rows.Count; i++)

return lst ;


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: