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
Marius Vasile
594
1.9k
145.6k
jquery autocomplete with .ashx not working with masterpage
Apr 24 2020 12:37 PM
I used the same approach for normal .aspx pages, I try to use masterpage and take advantage of a navbar using bootstrap. Everything whent well until I reached the autocomplete. I have to use .ashx file because I have multiple instances when using the same jquery and this makes it easier. I have no errors, but the autocomplete is not doing its job
The master page looks like this:
@ Master Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"WAPReview.master.cs"
Inherits=
"WAPReview.WAPReview"
%>
<!DOCTYPE html>
<html lang=
"en"
>
<head runat=
"server"
>
<title>Title</title>
<link rel=
"stylesheet"
href=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
/>
<link href=
"/Scripts/jquery-ui.css"
rel=
"stylesheet"
/>
<script type=
"text/javascript"
src=
"/Scripts/jquery-3.4.1.js"
></script>
<script type=
"text/javascript"
src=
"/Scripts/jquery-ui.js"
></script>
<asp:ContentPlaceHolder ID=
"Head"
runat=
"server"
>
</asp:ContentPlaceHolder>
</head>
<body>
<form runat=
"server"
>
<div id=
"nav"
>
<nav
class
=
"navbar navbar-expand bg-primary navbar-dark"
>
<a
class
=
"navbar-brand"
href=
"/HomePage.aspx"
>SAWCOD</a>
<!-- Links -->
<ul
class
=
"navbar-nav"
>
<li
class
=
"nav-item"
>
<a
class
=
"nav-link"
href=
"/HomePage.aspx"
>Home</a>
</li>
<li
class
=
"nav-item"
>
<a
class
=
"nav-link"
href=
"/IssueWAP/WAPControl.aspx"
>WAP Control</a>
</li>
<li
class
=
"nav-item"
>
<a
class
=
"nav-link"
href=
"/ReviewWAP/ReviewWAP.aspx"
>WAP Review</a>
</li>
<!-- Dropdown 1 -->
<li
class
=
"nav-item dropdown"
>
<a
class
=
"nav-link dropdown-toggle"
href=
"#"
id=
"navbardrop1"
data-toggle=
"dropdown"
>
WAP Report
</a>
<div
class
=
"dropdown-menu"
>
<a
class
=
"dropdown-item"
href=
"/RepWAP/WAPReport.aspx"
>WAP Report</a>
<a
class
=
"dropdown-item"
href=
"/RepWAP/WAPReviewReport.aspx"
>WAP Review Report</a>
</div>
</li>
<!-- Dropdown 2 -->
<li
class
=
"nav-item dropdown"
>
<a
class
=
"nav-link dropdown-toggle"
href=
"#"
id=
"navbardrop2"
data-toggle=
"dropdown"
>
Dashboard
</a>
<div
class
=
"dropdown-menu"
>
<a
class
=
"dropdown-item"
href=
"/Dashboard/WAPReviewed.aspx"
>WAP Reviewed</a>
<a
class
=
"dropdown-item"
href=
"/Dashboard/WAPIssued.aspx"
>WAP Issued</a>
</div>
</li>
<!-- Dropdown 3 -->
<li
class
=
"nav-item dropdown"
>
<a
class
=
"nav-link dropdown-toggle"
href=
"#"
id=
"navbardrop3"
data-toggle=
"dropdown"
>
Update Data
</a>
<div
class
=
"dropdown-menu"
>
<a
class
=
"dropdown-item"
href=
"/Update/Update.aspx"
>Update Data</a>
<a
class
=
"dropdown-item"
href=
"/UserUpdate/UserUpdate.aspx"
>User Update</a>
</div>
</li>
</ul>
<div
class
=
"form-inline my-2 my-lg-0 ml-auto"
>
<input
class
=
"form-control"
type=
"search"
placeholder=
"Enter WAP No"
aria-label=
"Search"
/>
<button
class
=
"btn btn-outline-light btn-md my-2 my-sm-0 ml-3"
type=
"submit"
>Search</button>
</div>
</nav>
</div><br /><br />
<asp:ContentPlaceHolder ID=
"MainContent"
runat=
"server"
>
</asp:ContentPlaceHolder>
<hr />
<footer
class
=
"container-fluid"
>
<div
class
=
"row h-100 justify-content-center align-items-center"
>
<p>© <%: DateTime.Now.Year %> - Southern Area Well Completion Operation Department</p>
</div>
</footer>
</form>
<script src=
"Scripts/errorValidation.js"
></script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
></script>
<script src=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
></script>
</body>
</html>
.ashx and jquery are:
(function ($) {
$(document).ready(function () {
$(
'#IssuerBN'
).autocomplete({
source:
'IssuerHandler.ashx'
});
});
})(jQuery);
using
System;
using
System.Collections.Generic;
using
System.Configuration;
using
System.Data;
using
System.Data.SqlClient;
using
System.Web;
using
System.Web.Script.Serialization;
namespace
WAPReview
{
/// <summary>
/// Summary description for IssuerHandler
/// </summary>
public
class
IssuerHandler : IHttpHandler
{
public
void
ProcessRequest(HttpContext context)
{
string
term = context.Request[
"term"
] ??
""
;
List<
string
> txtIssuerBN =
new
List<
string
>();
string
connString = ConfigurationManager.ConnectionStrings[
"ConnString"
].ConnectionString;
//string connString = Properties.Settings.Default.ConnectionString.ToString();
using
(SqlConnection conn =
new
SqlConnection(connString))
{
SqlCommand cmd =
new
SqlCommand(
"selectIssuerBN"
, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@IssuerBN"
, term);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while
(dr.Read())
{
txtIssuerBN.Add(dr[
"IssuerBN"
].ToString());
}
}
JavaScriptSerializer js =
new
JavaScriptSerializer();
context.Response.Write(js.Serialize(txtIssuerBN));
}
public
bool
IsReusable
{
get
{
return
false
;
}
}
}
}
and webpage:
<%@ Page Language=
"C#"
MasterPageFile=
"~/WAPReview.Master"
AutoEventWireup=
"true"
CodeBehind=
"ReviewWAP.aspx.cs"
Inherits=
"WAPReview.ReviewWAP"
%>
<asp:Content ID=
"Content1"
ContentPlaceHolderID=
"Head"
runat=
"server"
>
<script src=
"/Scripts/SearchIssuerBN.js"
type=
"text/javascript"
></script>
<script src=
"/Scripts/SearchReceiverCN.js"
type=
"text/javascript"
></script>
<script src=
"/Scripts/errorValidation.js"
type=
"text/javascript"
></script>
</asp:Content>
<asp:Content ID=
"Content4"
ContentPlaceHolderID=
"MainContent"
runat=
"server"
>
<asp:ScriptManager runat=
"server"
EnablePartialRendering=
"true"
></asp:ScriptManager>
<div
class
=
"container"
>
....................................
<asp:UpdatePanel ID=
"UpdatePanel1"
runat=
"server"
UpdateMode=
"Conditional"
>
<ContentTemplate>
<div id=
"Issuer2"
class
=
"row no-gutters"
>
<div
class
=
"col"
>
<div
class
=
"row no-gutters"
>
<div
class
=
"col-12"
>
<asp:Label
class
=
"form-control badge-success"
ID=
"Label50"
runat=
"server"
Text=
"Task Issuer"
/>
</div>
</div>
<div
class
=
"row no-gutters"
>
<div
class
=
"col-4"
>
<asp:Label
class
=
"form-control badge-primary"
ID=
"Label52"
runat=
"server"
Text=
"Issuer BN"
/>
<asp:TextBox
class
=
"form-control"
ID=
"IssuerBN"
runat=
"server"
AutoPostBack=
"True"
OnTextChanged=
"GetIssuerName"
/>
<asp:RequiredFieldValidator id=
"val13"
runat=
"server"
style=
"display:none"
ControlToValidate=
"IssuerBN"
/>
</div>
<div
class
=
"col-8"
>
<asp:Label
class
=
"form-control badge-primary"
ID=
"Label53"
runat=
"server"
Text=
"Issuer Name"
/>
<asp:TextBox
class
=
"form-control"
ID=
"IssuerName"
runat=
"server"
ReadOnly=
"true"
/>
<asp:RequiredFieldValidator id=
"val14"
runat=
"server"
style=
"display:none"
ControlToValidate=
"IssuerName"
/>
</div>
</div>
</div>
<div
class
=
"col"
>
<div
class
=
"row no-gutters"
>
<div
class
=
"col-12"
>
<asp:Label
class
=
"form-control badge-success"
ID=
"Label51"
runat=
"server"
Text=
"Task Receiver"
/>
</div>
</div>
<div
class
=
"row no-gutters"
>
<div
class
=
"col-4"
>
<asp:Label
class
=
"form-control badge-primary"
ID=
"Label54"
runat=
"server"
Text=
"Receiver CN"
/>
<asp:TextBox
class
=
"form-control"
ID=
"ReceiverCN"
runat=
"server"
AutoPostBack=
"True"
OnTextChanged=
"GetReceiverName"
/>
<asp:RequiredFieldValidator id=
"val15"
runat=
"server"
style=
"display:none"
ControlToValidate=
"ReceiverCN"
/>
</div>
<div
class
=
"col-8"
>
<asp:Label
class
=
"form-control badge-primary"
ID=
"Label55"
runat=
"server"
Text=
"Receiver Name"
/>
<asp:TextBox
class
=
"form-control"
ID=
"ReceiverName"
runat=
"server"
ReadOnly=
"true"
/>
<asp:RequiredFieldValidator id=
"val16"
runat=
"server"
style=
"display:none"
ControlToValidate=
"ReceiverName"
/>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
This time I was not able to find a solution since morning
Reply
Answers (
3
)
Convert PowerpointFile into HTML file format using C#
The Angular CLI process did not start listening for requests