I’ve got a simple textbox on my asp.net page wrapped around an updatepanel:
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtShipToName" runat="server"
ToolTip="Enter a name such as a company name or contact name."
MaxLength="50"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
Trying to implement autocomplete…so I created an .ashx file (an IHttpHandler) like so:
public class LoadAddress : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
DataSet ds;
Dictionary<long, string> lstAddresses = new Dictionary<long, string>();
ds = BL.GetAddresses(string.Empty, "both", 0, 100); //just snatching some data...
foreach(DataRow dr in ds.Tables[0].Rows)
{
lstAddresses.Add(Convert.ToInt64(dr["AddressID"].ToString()), dr["Name"].ToString());
}
StringBuilder builder = new StringBuilder();
foreach (KeyValuePair<long, string> item in lstAddresses)
{
builder.Append(string.Format("{0}|{1}|{2}",
item.Value,
item.Key,
Environment.NewLine));
}
context.Response.Write(builder.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
But I’m not sure how to call it in jquery, I tried:
$("#<%= txtShipToName.ClientID %>").autocomplete('LoadAddress.ashx').
result(function (event, data, formatted) { // data[0] : Address, data[1] : Address ID
});
But result is undefined, notice this method doesnt even exist…how can I call LoadAddress.ashx?
Edit
I added into the web config file:
<httpHandlers>
<add verb="*" path="LoadAddress.ashx" type="MyShipper.LoadAddress"/>
</httpHandlers>
But the autocomplete doesnt seem to work…in the jquery I changed it to simply:
$("#<%= txtShipToName.ClientID %>").autocomplete('LoadAddress.ashx');
But like I said no autocomplete is coming up. No errors in the developers tools in chrome.
What could I be missing?
Have you registered your
LoadAddresshandler in the web.config?(iis 6):
(and for iis 7+):