hi guyes trying read data webmethod , pass value lable in aspx page. take use of ajax , webmethod. problem when not able bind data on success lable controle.
my .asmx page.
public static string str; [webmethod] public string getemployeedetail(string name) { str = name; get(str); string daresult; daresult = get(str); return daresult; } [webmethod] public string get(string str) { list<string> rst = new list<string>(); using (sqlconnection con = new sqlconnection("...")) { using (sqlcommand cmd = new sqlcommand("select practice_short_name practice_detail practice_name = '" + str + "'",con)) { con.open(); sqldatareader dr = cmd.executereader(); while(dr.read()) { rst.add(string.format("{0}", dr["practice_short_name"])); } system.web.script.serialization.javascriptserializer jsearializer = new system.web.script.serialization.javascriptserializer(); return jsearializer.serialize(rst); } } }
and here ajax call function in aspx page.
function fun() { var ddlpsn = document.getelementbyid("<%=ddlpsn.clientid%>"); $(ddlpsn).change(function () { var s = $(this).val(); $.ajax({ type: 'post', url: 'autocompleteservice.asmx/getemployeedetail', data: '{name: "' + s + '" }', datatype: 'json', contenttype: 'application/json; charset=utf-8', success: function (data) { //i think need changes in here not getting do. $('#lblpriority').text(data.val); }, error: function (error) { console.log(error); } }); }); };
you need change data.val
data.d
. data returned webmethod
contained in d
property if have not explicitly defined own property returned data.
$('#lblpriority').text(data.d);
you need make webmethod
static
in order called ajax
.
Comments
Post a Comment