Do not use Web services (service) To implement text box automatic extension _ Practical Tips

Source: Internet
Author: User

The Autocompleteextender feature, which used to write Ajax, requires a WCF service or a Web service data source. But in a system, many text boxes want to use the AutoComplete function. We can't write a lot of service, like some smaller data. Do we have a way to replace it? That's for sure. The following demo, insus.net to implement the Autocompete extender function of a text box without writing a service.

First get the number from the database, you can write SQL statements, or write stored procedures, the following is to get the domain user information, imitation Outlook enter the recipient effect.

The information in the [Activedirectoryinfo] table is periodically synchronized with the Active Directory of the domain.

Copy Code code as follows:

Usp_activedirectoryinfo_getdisplaynameforservice
SET ANSI_NULLS on
Go
SET QUOTED_IDENTIFIER ON
Go
-- =============================================
--Author:Insus.NET
--Create date:2013-03-28
--description:get dissplay name Form Web Service
-- =============================================
CREATE PROCEDURE [dbo]. [Usp_activedirectoryinfo_getdisplaynameforservice]
(
@PrefixText NVARCHAR (MAX),
@Count INT
)
As
DECLARE @W NVARCHAR (MAX) = @PrefixText + '% '
EXECUTE (' SELECT top (' + @Count + ') [DisplayName] from [dbo].[ Activedirectoryinfo] WHERE [displayName] like ' + @w + ' ')

At the logical level, we write a category to interact with the data tier:
Copy Code code as follows:

Using System;
Using System.Collections.Generic;
Using System.Data;
Using System.Linq;
Using System.Web;

<summary>
Summary description for Activedirectoryinfo
</summary>
Namespace Insus.net
{
public class Activedirectoryinfo
{
Businessbase objbusinessbase = new Businessbase ();

Public Activedirectoryinfo ()
{
//
Todo:add constructor Logic here
//
}

Public DataTable GetDisplayName (string prefixtext,int count)
{
Parameter[] Parameter = {
New Parameter ("@PrefixText", Sqldbtype.nvarchar,-1,prefixtext),
New Parameter ("@Count", Sqldbtype.int,4,count)
};
Return Objbusinessbase.getdatatodataset ("Usp_activedirectoryinfo_getdisplaynamebyprefixtext", parameter). Tables[0];
}
}
}

One of the objects in the above category is Businessbase
Put ScriptManager
Copy Code code as follows:

<asp:scriptmanager id= "ScriptManager1" runat= "Server" ></asp:ScriptManager>

or Toolkitscriptmanager
Copy Code code as follows:

<ajaxtoolkit:toolkitscriptmanager id= "ToolkitScriptManager1" runat= "Server"/>

Pull to the Web page.

The following figure is the HTML and CS program, which requires two lines of code before the method:

Copy Code code as follows:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]


Effect:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.