Hello in this post i will show how to use ajax autocomplete extender in asp.net.
1. Add ajaxtoolkit namepace in the header of the aspx page.
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
2. Then add asp.net textbox control , Ajax ToolkitScriptManager, Ajax AutoCompleteExtender controls to the aspx page.
3. Below is code after adding all the controls :
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="AutoCompleteExtender1"
TargetControlID="txtSearch"
runat="server" ServiceMethod="GetSearchList" UseContextKey="True" />
1. Add ajaxtoolkit namepace in the header of the aspx page.
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
2. Then add asp.net textbox control , Ajax ToolkitScriptManager, Ajax AutoCompleteExtender controls to the aspx page.
3. Below is code after adding all the controls :
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="AutoCompleteExtender1"
TargetControlID="txtSearch"
runat="server" ServiceMethod="GetSearchList" UseContextKey="True" />
4. In the codebehind we will write the code for GetSearchList method. This method signature we enter into the autocompleteextender ServiceMethod property.
Above the method name we will write and method should be static.
[System.Web.Services.WebMethodAttribute()]
[System.Web.Script.Services.ScriptMethodAttribute()]
**This method signature and the method description we can also auto generate as show below:
Click on Add AutoComplete Page method.
In the method im using a linq query which will return me the result set of the all the words starting with the entered text in the textbox.
5. Run the project to check the Final Result
No comments:
Post a Comment