Wednesday, 23 March 2011

How To Used AutoCompleteExtender in Asp.net

Download AjaxControlToolkit.dll 
Add the Dll in the ToolBox Item
Add One Web-Service WebService.asmx
-----------------Design page
<body>
    <form id="form1" runat="server" autocomplete="off">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
              <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="UseAutoComplete"
                    ServicePath="WebService.asmx" TargetControlID="TextBox1" MinimumPrefixLength="0">
                </cc1:AutoCompleteExtender>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
-----------------WebService.cs Code


using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Web.SessionState;
using System.Collections.Generic;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService {
    public WebService () {
    }
    [WebMethod]
    public string[] UseAutoComplete(string prefixText, int count)
    {
        count = 10;
        List<string> responses = new List<string>();
        for (int i = 0; i < count; i++)
            responses.Add(prefixText + (char)(i + 65));
        return responses.ToArray();
    }  
}
--------Add This In WebConfig File
  <system.web.extensions>
    <scripting>
      <webServices>
        <!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
        <!--
      <jsonSerialization maxJsonLength="500">
        <converters>
          <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
        </converters>
      </jsonSerialization>
      -->
        <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
        <!--
        <authenticationService enabled="true" requireSSL = "true|false"/>
      -->
        <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
           and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and
           writeAccessProperties attributes. -->
        <!--
      <profileService enabled="true"
                      readAccessProperties="propertyname1,propertyname2"
                      writeAccessProperties="propertyname1,propertyname2" />
      -->
      </webServices>
      <!--
      <scriptResourceHandler enableCompression="true" enableCaching="true" />
      -->
    </scripting>
  </system.web.extensions>

No comments:

Post a Comment

Get all non-clustered indexes

DECLARE cIX CURSOR FOR     SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID         FROM Sys.Indexes SI             ...