TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Fulufhelo Munyai
NA
33
3.2k
AutoComplete Textbox
Sep 11 2015 4:21 AM
Hi guys, i am trying to do the auto complete textbox using entity data model but i am getting this error "parsererror" please help, bellow is my code:
aspx Code
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AutoComplete._Default" %>
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script lang="javascript" type="text/javascript">
$(function () {
$('#<%=txtCompanyName.ClientID%>').autocomplete({
source: function (request, response) {
$.ajax({
url: "Default.aspx/GetCompanyName",
data: "{'pre':'"+ request.term +"'}",
dataType: "json",
type: "POST",
constentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d,function(item)
{
return {value : item}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
});
});
</script>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<h3>Auto Complete</h3>
<table>
<tr>
<td>Type Company Name: </td>
<td>
<div class="ui-widget" style="text-align-last:left">
</div>
</td>
</tr>
</table>
<div class="ui-widget" style="text-align-last:left">
<asp:TextBox ID="txtCompanyName" runat="server" CssClass="textboxAuto" Width="350px" Font-Size="12px"></asp:TextBox>
</div>
</asp:Content>
aspx.cs Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AutoComplete
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
[ScriptMethod(ResponseFormat= ResponseFormat.Json)]
public static List<string> GetCompanyName(string pre)
{
List<string> allCompanyName = new List<string>();
using (MyDatabaseEntities dc = new MyDatabaseEntities ())
{
allCompanyName = (from a in dc.TopCompanies
where a.CompanyName.StartsWith(pre)
select a.CompanyName).ToList();
}
return allCompanyName;
}
}
}
Reply
Answers (
5
)
how can we remove the selection
ASP.NET