As a software engineer, just now i am learning the Kendo UI, to implement in our future project.
If i call a page method from ajax ($.ajax), and create a data source, and supply that datasource to the kendo autocomplete, then it works fine.
But I am trying to connect to an Asp Net page method from within a datasource which is inside a kendo autocomplete. Because I am planning to extensively follow this approach in Grid paging, filtering and sorting etc.
But the page method is never called at all. Herewith I show the code.
Client Side:
var _rootUrl = '<%=string.Format("{0}{1}/", Request.Url.GetLeftPart(UriPartial.Authority), HttpRuntime.AppDomainAppVirtualPath)%>';
$(document).ready(function()
{
$("#TxtName").kendoAutoComplete(
{
minLength: 1,
dataTextField: "Name",
dataSource:
{
transport:
{
read:
{
type: "POST",
url: _rootUrl + "AutoComplete/Default7.aspx/GetEmployeesNames",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}"
}
},
schema:
{
data: function(data)
{
return JSON.parse(data.d);
}
}
}
});
});
Server Side Asp Net Page Method:
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static string GetEmployeesNames()
{
string StrConnectionString = ConfigurationManager.ConnectionStrings["ConnectionStringEmployeesNormalized2"].ConnectionString;
SqlConnection SqlConnection1 = new SqlConnection(StrConnectionString);
SqlCommand SqlCommand1 = new SqlCommand("SELECT Id, Name FROM dbo.Employees ", SqlConnection1);
DataTable DataTable1 = new DataTable();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(SqlCommand1);
SqlDataAdapter1.Fill(DataTable1);
List<Employee> List1 = new List<Employee>();
foreach (DataRow DataRow1 in DataTable1.Rows)
{
List1.Add(new Employee(Convert.ToInt32(DataRow1["Id"]), Convert.ToString(DataRow1["Name"])));
}
string JsonText = (new JavaScriptSerializer()).Serialize(List1);
HttpContext.Current.Response.ContentType = "application/json";
return JsonText;
}
Could you please help me?
If i call a page method from ajax ($.ajax), and create a data source, and supply that datasource to the kendo autocomplete, then it works fine.
But I am trying to connect to an Asp Net page method from within a datasource which is inside a kendo autocomplete. Because I am planning to extensively follow this approach in Grid paging, filtering and sorting etc.
But the page method is never called at all. Herewith I show the code.
Client Side:
var _rootUrl = '<%=string.Format("{0}{1}/", Request.Url.GetLeftPart(UriPartial.Authority), HttpRuntime.AppDomainAppVirtualPath)%>';
$(document).ready(function()
{
$("#TxtName").kendoAutoComplete(
{
minLength: 1,
dataTextField: "Name",
dataSource:
{
transport:
{
read:
{
type: "POST",
url: _rootUrl + "AutoComplete/Default7.aspx/GetEmployeesNames",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}"
}
},
schema:
{
data: function(data)
{
return JSON.parse(data.d);
}
}
}
});
});
Server Side Asp Net Page Method:
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static string GetEmployeesNames()
{
string StrConnectionString = ConfigurationManager.ConnectionStrings["ConnectionStringEmployeesNormalized2"].ConnectionString;
SqlConnection SqlConnection1 = new SqlConnection(StrConnectionString);
SqlCommand SqlCommand1 = new SqlCommand("SELECT Id, Name FROM dbo.Employees ", SqlConnection1);
DataTable DataTable1 = new DataTable();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(SqlCommand1);
SqlDataAdapter1.Fill(DataTable1);
List<Employee> List1 = new List<Employee>();
foreach (DataRow DataRow1 in DataTable1.Rows)
{
List1.Add(new Employee(Convert.ToInt32(DataRow1["Id"]), Convert.ToString(DataRow1["Name"])));
}
string JsonText = (new JavaScriptSerializer()).Serialize(List1);
HttpContext.Current.Response.ContentType = "application/json";
return JsonText;
}
Could you please help me?