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
Dharam Rai
NA
383
22.6k
How to make jquery autocomplete works from usercontrol using
Apr 13 2020 10:06 PM
I have jQuery to pull the autocomplete record as I type in the textbox, this data is being fetched using webservice. Now, everything works fine while using in Default.aspx page, but when I use this process from UserControl.ascx and call it in the default.aspx page then it doesn't return the autocomplete data (result).
WebService.asmx code:
[WebMethod]
public
List<
string
> GetAutoCompleteData(
string
username)
{
string
conString = ConfigurationManager.ConnectionStrings[
"MYCONNECTION"
].ConnectionString;
List<
string
> result =
new
List<
string
>();
using
(SqlConnection con =
new
SqlConnection(conString))
{
using
(SqlCommand cmd =
new
SqlCommand(
"select DISTINCT SSName from SSRecord where SSName LIKE '%'+@SearchText+'%'"
, con))
{
con.Open();
cmd.Parameters.AddWithValue(
"@SearchText"
, username);
SqlDataReader dr = cmd.ExecuteReader();
while
(dr.Read())
{
result.Add(dr[
"SSName "
].ToString());
}
return
result;
}
}
}
UserControl.ascx code:
<script src=
"jquery-1.11.2.js"
type=
"text/javascript"
></script>
<link href=
"jquery-ui.css"
rel=
"stylesheet"
/>
<script src=
"jquery-ui.js"
type=
"text/javascript"
></script>
<script type=
"text/javascript"
>
$(document).ready(
function
() {
SearchText();
});
function
SearchText() {
$(
".autosuggest"
).autocomplete({
source:
function
(request, response) {
$.ajax({
type:
"POST"
,
contentType:
"application/json; charset=utf-8"
,
url:
"WebService.asmx/GetAutoCompleteData"
,
data:
"{'username':'"
+ document.getElementById('txtSearch
').value + "'
}",
dataType:
"json"
,
success:
function
(data) {
response(data.d);
},
error:
function
(result) {
alert(
"Error"
);
}
});
}
});
}
</script>
<label
for
=
"tbAuto"
>Enter UserName: </label>
<asp:TextBox ID=
"txtSearch"
runat=
"server"
class
=
"autosuggest"
></asp:TextBox>
Default.aspx code:
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeFile=
"Default.aspx.cs"
Inherits=
"_Default"
%>
<%@ Register Src=
"~/UserControl.ascx"
TagPrefix=
"uc1"
TagName=
"UserControl"
%>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<uc1: UserControl runat=
"server"
ID=
"UserControl"
/>
</div>
</form>
</body>
Reply
Answers (
4
)
html.Dropdownlist
its only my .mkv files everything else works perfectly.