Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two textboxes, both with autocomplete extender.after selecting value from first textbox, and start typing into second textbox it should suggest the value only related to first textbox value . when i start typing into second textbox its not firing the webmethod...
Here is my code...
XML
<asp:TextBox ID="txtClientUser" runat="server" ClientIDMode="Static" onChange="$find('AutoCompleteExtender5').set_contextKey(this.value);" onblur="checkClientSelected(this)"></asp:TextBox>
                                           <ajax:AutoCompleteExtender ID="AutoCompleteExtender4" runat="server" TargetControlID="txtClientUser"
                                           CompletionInterval="10" CompletionSetCount="100" MinimumPrefixLength="1" EnableCaching="false"
                                           ServiceMethod="GetClientName" ServicePath="~/CMSAdmin/frmClientMaster_New.aspx" OnClientItemSelected="ClientNameSelected" FirstRowSelected="false"></ajax:AutoCompleteExtender>



XML
<asp:TextBox ID="txtAdd1User" runat="server" onkeyup="SetContextKey()" onblur="CheckAddressSelected(this)"></asp:TextBox>
                                            <ajax:AutoCompleteExtender ID="AutoCompleteExtender5" runat="server" TargetControlID="txtAdd1User"
                                           CompletionInterval="10" CompletionSetCount="100" EnableCaching="false" ServiceMethod="GetAddressName"
                                           ServicePath="~/CMSAdmin/frmClientMaster_New.aspx" OnClientItemSelected="AddressSelected" UseContextKey="true"></ajax:AutoCompleteExtender>


C#
[System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetAddressName(string prefixText, string ClientId)
    {
        SqlConnection conn = ApplicationInfo.GetConnection();
        List<string> AddressName = new List<string>();
        try
        {
            DataTable dt = AddressManager.Search_AddressName(conn, prefixText, ClientId).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string Item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i]["AddressName"].ToString(), dt.Rows[i]["AddressId"].ToString());
                AddressName.Add(Item);
            }
            
        }
        catch (Exception ex)
        {

        }
        finally
        {
            conn.Close();
            conn.Dispose();
        }
        return AddressName;
    }
Posted
Updated 26-Jul-15 23:28pm
v3

1 solution

<ajax:autocompleteextender id="AutoCompleteExtender5" runat="server" targetcontrolid="txtAdd1User" xmlns:ajax="#unknown">
CompletionInterval="10" CompletionSetCount="100" EnableCaching="false" ServiceMethod="GetAddressName"
ServicePath="~/CMSAdmin/frmClientMaster_New.aspx" OnClientItemSelected="AddressSelected" UseContextKey="true" OnClientPopulating="App_Context_Key">


//Use OnClientPopulating="App_Context_Key" Property


Javascript;
function Appt_Context_Key(source, e) {
source.set_contextKey($get("<%=ddlControl.ClientID%>").value);
}
// User Pipe Symbol for Multiple
// Like source.set_contextKey($get("<%=ddlControl2.ClientID%>").value+'|'+$get("&lt;%=ddlControl.ClientID%&gt;").value);


//Web Method
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List&amp;lt;string&amp;gt; GetAddressName(string prefixText, string ClientId,string contextKey)
{
SqlConnection conn = ApplicationInfo.GetConnection();
List&amp;lt;string&amp;gt; AddressName = new List&amp;lt;string&amp;gt;();
try
{
DataTable dt = AddressManager.Search_AddressName(conn, prefixText, ClientId).Tables[0];
for (int i = 0; i &amp;lt; dt.Rows.Count; i++)
{
string Item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i]["AddressName"].ToString(), dt.Rows[i]["AddressId"].ToString());
AddressName.Add(Item);
}

}
catch (Exception ex)
{

}
finally
{
conn.Close();
conn.Dispose();
}
return AddressName;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900