.

Lookup by combining a ajaxToolkit:AutoCompleteExtender and standalone webservice asmx file

 /* ASP.NET/HTML CODE FOR CONTROL  */

 

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LookupPerson.ascx.cs" Inherits="CliniwebAdmin.CustomControls.LookupPerson" %>

    <script type="text/javascript">

        function Test(sender, e) {
            __doPostBack("AutoCompleteExtender1", sender._element.value);
        }
             
        
    </script>
<div class="fullwidthrow">
            <div class="inlineCellPadded" style="width: 240px;">
                Author</div>
            <div class="inlineCell" style="width: 351px;">
                <asp:TextBox ID="TextBoxAuthors" runat="server" TextMode="SingleLine" Width="340px"
                    AutoPostBack="true" OnTextChanged="TextBoxAuthors_TextChanged" Text="" ></asp:TextBox>
                    <asp:TextBox ID="TextBoxAuthorid" runat="server" style="display:none" ></asp:TextBox>
               <asp:TextBox ID="TextBoxAuthorDivisionid" runat="server" style="display:none" ></asp:TextBox>
                <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBoxAuthors"
                    ServiceMethod="GetPersonList" ServicePath="../LookupWebService.asmx" MinimumPrefixLength="2"
                    CompletionInterval="100" EnableCaching="true" CompletionSetCount="20" CompletionListCssClass=""
                    CompletionListItemCssClass="" CompletionListHighlightedItemCssClass="" DelimiterCharacters=";, :"
                    ShowOnlyCurrentWordInCompletionListItem="true" OnClientItemSelected="Test">
                </ajaxToolkit:AutoCompleteExtender>
            </div>
            <div class="inlineCell" style="width: 372px;">
            </div>
</div>


    <asp:UpdatePanel ID="UpdatePanelnewauth" runat="server" >
        <ContentTemplate>
            <asp:Button Style="display: none" ID="ButtonFAKE" runat="server" Text="Button" />
            <asp:Panel ID="PanelNewAuth" runat="server" Style="display: none" CssClass="modalPopup"
                Width="432px" Height="300px">
                <div style="cursor: move; background-color: #DDDDDD; border: solid 1px Gray; color: Black;
                    height: 100%">
                    <p>
                        New Person detected</p>
                    <p>
                        Please provide information below:
                    </p>
                    <table>
                    <tr><td>First name: </td><td>
                        <asp:TextBox ID="TextBoxNewPersonFirstname" runat="server"></asp:TextBox></td></tr>
                    <tr><td>Last name: </td><td>
                        <asp:TextBox ID="TextBoxNewPersonLastname" runat="server"></asp:TextBox></td></tr>
                    <tr><td>Email: </td><td>
                        <asp:TextBox ID="TextBoxNewPersonEmail" runat="server"></asp:TextBox></td></tr>
                    </table>
                    <br />
                    <asp:Button ID="NewAuthOk" runat="server" Text="Ok" OnClick="NewAuthOk_Click" />
                    <asp:Button ID="NewAuthCancel" runat="server" Text="Cancel" OnClick="NewAuthCancel_Click" />
                </div>
            </asp:Panel>
            <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderNewAuth" runat="server" PopupControlID="PanelNewAuth"
                TargetControlID="ButtonFAKE" BackgroundCssClass="modalBackground" DropShadow="True"
>
            </ajaxToolkit:ModalPopupExtender>
        </ContentTemplate>
    </asp:UpdatePanel>

 

 /* CODE BEHIND CONTROL  */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CliniwebAdmin.CustomControls
{
    public partial class LookupPerson : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void NewAuthOk_Click(object sender, EventArgs e)
        {
            Kingsweb2DataAccess.Kingsweb2DataClassesDataContext newdb = new Kingsweb2DataAccess.Kingsweb2DataClassesDataContext();
            try
            {
                Kingsweb2DataAccess.Person p = new Kingsweb2DataAccess.Person();
                p.FirstName = TextBoxNewPersonFirstname.Text;
                p.LastName = TextBoxNewPersonLastname.Text;
                p.Email = TextBoxNewPersonEmail.Text;
                p.Id = Guid.NewGuid();
                p.AuditCreate = DateTime.Now;
                p.AuditAlter = DateTime.Now;
                newdb.Persons.InsertOnSubmit(p);
                newdb.SubmitChanges();

                TextBoxAuthors.Text = p.FirstName + " " + p.LastName;
                //TextBoxAuthorEmail.Text = p.Email;
                //TextAuthorDivision.Text = "unknown";
                //TextBoxAuthorSpeciality.Text = "unknown";
                //TextBoxCustodianEmail.Text = "unknown";
                //TextBoxCustodianJobTitle.Text = "unknown";
                //TextBoxCustodianName.Text = "unknown";

                //UpdatePaneldetails.Update();
                ModalPopupExtenderNewAuth.Hide();
            }
            catch { }

        }


        protected void NewAuthCancel_Click(object sender, EventArgs e)
        {
            TextBoxAuthors.Text = "";
            //TextBoxAuthorEmail.Text = "";
            //TextAuthorDivision.Text = "";
            //TextBoxAuthorSpeciality.Text = "";
            //TextBoxCustodianEmail.Text = "";
            //TextBoxCustodianJobTitle.Text = "";
            //TextBoxCustodianName.Text = "";

            //UpdatePaneldetails.Update();
            ModalPopupExtenderNewAuth.Hide();
        }

        protected void TextBoxAuthors_TextChanged(object sender, EventArgs e)
        {
            string newauth = TextBoxAuthors.Text;
            Guid x = Kingsweb2DataAccess.ListFactory.getPersonID(newauth);
            if (x == new Guid())
            {
                int splitter = TextBoxAuthors.Text.IndexOf(" ");
                try
                {
                    TextBoxNewPersonFirstname.Text = TextBoxAuthors.Text.Substring(0, splitter);
                    TextBoxNewPersonLastname.Text = TextBoxAuthors.Text.Substring(splitter + 1);
                    TextBoxNewPersonEmail.Text = TextBoxNewPersonFirstname.Text + "." + TextBoxNewPersonLastname.Text + "@kch.nhs.uk";
                }
                catch
                {
                    TextBoxNewPersonFirstname.Text = "";
                    TextBoxNewPersonLastname.Text = "";
                }
                ModalPopupExtenderNewAuth.Show();
                //UpdatePanel1.Update();
            }
            else
            {
                TextBoxAuthorid.Text = x.ToString();
                Guid DivId = Kingsweb2DataAccess.ListFactory.getPersonDivisionID(x);
                TextBoxAuthorDivisionid.Text = DivId.ToString();
                //UpdatePanel4Author.Update();
            }
        }


    }
}

 

/* CODE FOR SERVICE*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections.Generic;
using System.Linq;
using System.Data ;

namespace KingWebService
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    [System.Web.Script.Services.ScriptServiceAttribute]
    public class LookupWebService : System.Web.Services.WebService
    {
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public string[] GetPersonList(string prefixText, int count)
        {
            List<string> ret = new List<string>();
           
            Kingsweb2DataAccess.Kingsweb2DataClassesDataContext newdb = new Kingsweb2DataAccess.Kingsweb2DataClassesDataContext();
            foreach (Kingsweb2DataAccess.Person p in newdb.Persons)
            {
                string fullname = p.FirstName + " " + p.LastName;
                if (fullname.ToLower().Contains(prefixText.ToLower()))
                    ret.Add(fullname);

                if (ret.Count > count)
                    break;
            }

            return ret.ToArray();
        }


    }
}

What's your thoughts on this?

*

Protected by WP Anti Spam