This article is used for web services using jquery asp.net.


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
jquery-1.7.min.js
jquery.ui.core.js
jquery.ui.widget.js
jquery.ui.position.js
jquery.ui.autocomplete.js
demos.css
jquery-ui.css

The java script function for aspx page.


$(function() {
$(".autoRefPhy").autocomplete({
source: function(request, response) {
$.ajax({
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) {
alert(textStatus);
}
});
},
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("'", "''") + "%' )";
else
_wherePhyClause = " ( name like '%" + HttpUtility.UrlDecode(prefixText).Replace("'", "''") + "%' )";


DataTable dtResNameLst = _objCConsultation.GetResourceNameAsDataTable(_wherePhyClause, out textField, out valueField);
getDataIntoSession(dtResNameLst);
List lst = new List();
string str = "";
for (int i = 0; i < dtResNameLst.Rows.Count; i++)
{
lst.Add(dtResNameLst.Rows[i]["Name"].ToString());
}

return lst ;
}


Comments

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:
    Email: