Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
comapanysearch.js file
$(document).ready(function () {

 var comapnysearch;
    $.ajax({ type: "POST",
        url: 'EmployeeDetails.aspx/comapanynamesearch',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function (msg) {
            companynames = msg.d;
        }
    });


comapanysearch.aspx code behind file
[WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string comapanynamesearch()
    {
        try
        {
            string strJson = string.Empty;
            abs_properties_getprofiledetails obp = new abs_properties_getprofiledetails();
            abs_sqldb_comapanysearch obl = new abs_sqldb_comapanysearch();
            stringjson json = new stringjson(); //stringjson is  class file.it convert datatable to string format..//
            DataTable dt = obl.getEmployeeDetails(obp);
            if (dt.Rows.Count > 0)
            {
                strJson = json.json_string(dt);
            }
            return strJson;
        }

        catch (Exception ex)
        {
            throw (ex);

        }


employeedetails.cs my class files
public override DataTable comapanynamesearch(abs_properties_getprofiledetails obj)
 {
     try
     {
         SqlConnection vcon = new SqlConnection();
         vcon.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
         SqlCommand vcmd = new SqlCommand();
         vcmd.Connection = vcon;
         vcmd.CommandType = CommandType.StoredProcedure;
         vcmd.CommandText = "getcomapanynames_sp";
         SqlDataAdapter sda = new SqlDataAdapter();
         DataTable dt = new DataTable();
         sda.Fill(dt);
      
         return dt;
     }
     catch (Exception ex)
     {
         throw (ex);

     }
 }
Posted
Updated 14-Apr-14 9:21am
v9
Comments
gggustafson 14-Apr-14 14:20pm    
How about formatting you code?
gggustafson 14-Apr-14 14:32pm    
I asked you to format your code, not provide further explainations.
srikanth492 14-Apr-14 14:40pm    
i have changed my format once check it..

1 solution

If you want your method to be able to be called by javascript, you need to add this attribute above the method signature:

[System.Web.Script.Services.ScriptService]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900