I would like to create a email address textbox similar to the one used in Gmail where my users can type an email address and the autocomplete will look in the database for a similar email address. Then, if one is found in the auto complete, or when the
user enters the full email address, a comma and space is autmomatically placed after the address so that the user may enter another email address.
However, after following it exactly and verifying that I do have data in my table to call, it is not working. I am using .NET 4.0 with SQL Server 2008.
I am not receiving any errors; it just simply does not work (nothing happens in my textbox). Any ideas?
Here is my code:
'''''''''''''''''''''Web service
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System
Imports System.Collections
'Imports System.Linq
'Imports System.Xml.Linq
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="https://www.mywebsite.com/mywebservices/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class AutoComplete
Inherits System.Web.Services.WebService
Dim cn As New SqlClient.SqlConnection()
Dim ds As New DataSet
Dim dt As New DataTable
<WebMethod()> _
Public Function GetCompletionList(ByVal prefixText As String, _
ByVal count As Integer) As String()
'ADO.Net
Dim ConnMem As String
ConnMem = ConfigurationManager.ConnectionStrings("ServiceString").ToString()
Dim SqlQueryMem As New SqlConnection(ConnMem)
Dim ResultsMem As New SqlCommand("SELECT Column1 FROM Table1 WHERE UserID = @UserID", SqlQueryMem)
ResultsMem.Parameters.AddWithValue("@UserID", HttpContext.Current.User.Identity.Name).Value = HttpContext.Current.User.Identity.Name
Try
cn.Open()
ResultsMem.ExecuteNonQuery()
Dim da As New SqlDataAdapter(ResultsMem)
da.Fill(ds)
Catch ex As Exception
Finally
cn.Close()
End Try
dt = ds.Tables(0)
'Then return List of string(txtItems) as result
Dim txtItems As New List(Of String)
Dim dbValues As String
For Each row As DataRow In dt.Rows
''String From DataBase(dbValues)
dbValues = row("Column1").ToString()
dbValues = dbValues.ToLower()
txtItems.Add(dbValues)
Next
Return txtItems.ToArray()
End Function
End Class
'''''''''''''''''''''ASPX page
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" EnableCaching="true"
BehaviorID="AutoCompleteEx" MinimumPrefixLength="2" TargetControlID="ToTextBox"
ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" CompletionInterval="1000"
CompletionSetCount="20" CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :" ShowOnlyCurrentWordInCompletionListItem="true">
<Animations>
<OnShow>
<Sequence>
<%-- Make the completion list transparent and then show it --%>
<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<%--Cache the original size of the completion list the first time
the animation is played and then set it to zero --%>
<ScriptAction Script="// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '0px';
}" />
<%-- Expand from 0px to the appropriate size while fading in --%>
<Parallel Duration=".4">
<FadeIn />
<Length PropertyKey="height" StartValue="0"
EndValueScript="$find('AutoCompleteEx')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<%-- Collapse down to 0px and fade out --%>
<Parallel Duration=".4">
<FadeOut />
<Length PropertyKey="height" StartValueScript=
"$find('AutoCompleteEx')._height" EndValue="0" />
</Parallel>
</OnHide>
</Animations>
</asp:AutoCompleteExtender>
Okay, I have got it working now. However, I need to add more funationality to it. As of now, it is looking for email addresses as it should.
What I would like to do is when a user selects an address from the autocomplete list, I want it to automatically add a coma and a space after the selected email address.
Thanks everyone for your reply. I have got it working with but I am needing to increase its functionality now.
I am trying to make it more like the Gmail autocomplete textbox for email addresses. I would like for the autocomplete to show both Display Name and the Email Address like the following:
Example:
John Smith
jsmith@email.com
Then, once the user selects the desired recipient, the folowing should be entered into the textbox:
jsmith@email.com,
Does anyone know how I can accomplish this? I am not real proficient with javascript so as much help as you can give is appreciated.
Here is the code I am currently using:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System
Imports System.Collections
'Imports System.Linq
'Imports System.Xml.Linq
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.SessionState.HttpSessionState
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="https://www.mysite.com/webservices/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class AutoComplete
Inherits System.Web.Services.WebService
Dim cn As New SqlClient.SqlConnection()
Dim ds As New DataSet
Dim dt As New DataTable
<WebMethod()> _
Public Function GetCompletionList(ByVal prefixText As String, _
ByVal count As Integer) As String()
Dim strCn As String = ConfigurationManager.ConnectionStrings("String").ToString()
cn.ConnectionString = strCn
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT Email, Name FROM List WHERE Email LIKE @myVariable AND UserName = @UserName"
cmd.Parameters.AddWithValue("@myVariable", "%" + prefixText + "%")
cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.User.Identity.Name).Value = HttpContext.Current.User.Identity.Name
Try
cn.Open()
cmd.ExecuteNonQuery()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
Catch ex As Exception
Finally
cn.Close()
End Try
dt = ds.Tables(0)
'Then return List of string(txtItems) as result
Dim txtItems As New List(Of String)
Dim dbValues As String
Dim dbValues2 As String
For Each row As DataRow In dt.Rows
''String From DataBase(dbValues)
dbValues = row("Email").ToString()
dbValues = dbValues.ToLower()
''String From DataBase(dbValues)
dbValues2 = row("Name").ToString()
dbValues2 = dbValues2.ToLower()
txtItems.Add("<b>" + dbValues2 + "</b><br />")
txtItems.Add(" " + dbValues)
Next
Return txtItems.ToArray()
End Function
mattcase
Member
375 Points
520 Posts
Email address comma seperaters
Nov 26, 2012 03:41 PM|LINK
Hi,
I would like to create a email address textbox similar to the one used in Gmail where my users can type an email address and the autocomplete will look in the database for a similar email address. Then, if one is found in the auto complete, or when the user enters the full email address, a comma and space is autmomatically placed after the address so that the user may enter another email address.
Does anyone know how I could do this?
Thanks.
asteranup
All-Star
30184 Points
4906 Posts
Re: Email address comma seperaters
Nov 27, 2012 03:28 AM|LINK
Hi,
Go to autocomplete
http://jqueryui.com/autocomplete/#multiple
and check multiple values.
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Email address comma seperaters
Nov 27, 2012 08:29 AM|LINK
You will need ajax or jQuery for this. Or both can be used. Use the ajax variables to get the value and to match it in database.
http://www.w3schools.com/ajax/ajax_database.asp
~~! FIREWALL !~~
mattcase
Member
375 Points
520 Posts
Re: Email address comma seperaters
Nov 29, 2012 03:43 PM|LINK
Thanks for your reply.
I have tried to implement an autocomplete method using the folloiwing example: http://www.codeproject.com/Articles/201099/AutoComplete-With-DataBase-and-AjaxControlToolkit
However, after following it exactly and verifying that I do have data in my table to call, it is not working. I am using .NET 4.0 with SQL Server 2008.
I am not receiving any errors; it just simply does not work (nothing happens in my textbox). Any ideas?
Here is my code:
'''''''''''''''''''''Web service Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System Imports System.Collections 'Imports System.Linq 'Imports System.Xml.Linq Imports System.Collections.Generic Imports System.Data Imports System.Data.SqlClient Imports System.Configuration ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. <System.Web.Script.Services.ScriptService()> _ <WebService(Namespace:="https://www.mywebsite.com/mywebservices/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ Public Class AutoComplete Inherits System.Web.Services.WebService Dim cn As New SqlClient.SqlConnection() Dim ds As New DataSet Dim dt As New DataTable <WebMethod()> _ Public Function GetCompletionList(ByVal prefixText As String, _ ByVal count As Integer) As String() 'ADO.Net Dim ConnMem As String ConnMem = ConfigurationManager.ConnectionStrings("ServiceString").ToString() Dim SqlQueryMem As New SqlConnection(ConnMem) Dim ResultsMem As New SqlCommand("SELECT Column1 FROM Table1 WHERE UserID = @UserID", SqlQueryMem) ResultsMem.Parameters.AddWithValue("@UserID", HttpContext.Current.User.Identity.Name).Value = HttpContext.Current.User.Identity.Name Try cn.Open() ResultsMem.ExecuteNonQuery() Dim da As New SqlDataAdapter(ResultsMem) da.Fill(ds) Catch ex As Exception Finally cn.Close() End Try dt = ds.Tables(0) 'Then return List of string(txtItems) as result Dim txtItems As New List(Of String) Dim dbValues As String For Each row As DataRow In dt.Rows ''String From DataBase(dbValues) dbValues = row("Column1").ToString() dbValues = dbValues.ToLower() txtItems.Add(dbValues) Next Return txtItems.ToArray() End Function End Class '''''''''''''''''''''ASPX page <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" EnableCaching="true" BehaviorID="AutoCompleteEx" MinimumPrefixLength="2" TargetControlID="ToTextBox" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" CompletionInterval="1000" CompletionSetCount="20" CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters=";, :" ShowOnlyCurrentWordInCompletionListItem="true"> <Animations> <OnShow> <Sequence> <%-- Make the completion list transparent and then show it --%> <OpacityAction Opacity="0" /> <HideAction Visible="true" /> <%--Cache the original size of the completion list the first time the animation is played and then set it to zero --%> <ScriptAction Script="// Cache the size and setup the initial size var behavior = $find('AutoCompleteEx'); if (!behavior._height) { var target = behavior.get_completionList(); behavior._height = target.offsetHeight - 2; target.style.height = '0px'; }" /> <%-- Expand from 0px to the appropriate size while fading in --%> <Parallel Duration=".4"> <FadeIn /> <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" /> </Parallel> </Sequence> </OnShow> <OnHide> <%-- Collapse down to 0px and fade out --%> <Parallel Duration=".4"> <FadeOut /> <Length PropertyKey="height" StartValueScript= "$find('AutoCompleteEx')._height" EndValue="0" /> </Parallel> </OnHide> </Animations> </asp:AutoCompleteExtender>Thanks.
RameshRajend...
Star
7983 Points
2099 Posts
Re: Email address comma seperaters
Nov 29, 2012 03:58 PM|LINK
Hai
Use Regex
http://stackoverflow.com/questions/4412725/how-to-match-a-comma-separated-list-of-emails-with-regex
http://stackoverflow.com/questions/6870223/regular-expression-to-validate-comma-separated-email-addresses
mattcase
Member
375 Points
520 Posts
Re: Email address comma seperaters
Nov 29, 2012 06:29 PM|LINK
Thanks for your reply.
Okay, I have got it working now. However, I need to add more funationality to it. As of now, it is looking for email addresses as it should.
What I would like to do is when a user selects an address from the autocomplete list, I want it to automatically add a coma and a space after the selected email address.
How do I do this?
Thanks.
raju dasa
Star
14412 Points
2452 Posts
Re: Email address comma seperaters
Nov 30, 2012 05:14 AM|LINK
Hi,
You have to use OnClientItemSelected on AutoCompleteExtender
check this site:
http://stackoverflow.com/questions/8297999/autocompleteextender-onclientitemselected-not-working-in-ie8-working-in-ie9-j
rajudasa.blogspot.com || blog@opera
mattcase
Member
375 Points
520 Posts
Re: Email address comma seperaters
Dec 11, 2012 02:13 PM|LINK
Thanks everyone for your reply. I have got it working with but I am needing to increase its functionality now.
I am trying to make it more like the Gmail autocomplete textbox for email addresses. I would like for the autocomplete to show both Display Name and the Email Address like the following:
Example:
John Smith
jsmith@email.com
Then, once the user selects the desired recipient, the folowing should be entered into the textbox:
jsmith@email.com,
Does anyone know how I can accomplish this? I am not real proficient with javascript so as much help as you can give is appreciated.
Here is the code I am currently using:
Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System Imports System.Collections 'Imports System.Linq 'Imports System.Xml.Linq Imports System.Collections.Generic Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Imports System.Web.SessionState.HttpSessionState ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. <System.Web.Script.Services.ScriptService()> _ <WebService(Namespace:="https://www.mysite.com/webservices/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ Public Class AutoComplete Inherits System.Web.Services.WebService Dim cn As New SqlClient.SqlConnection() Dim ds As New DataSet Dim dt As New DataTable <WebMethod()> _ Public Function GetCompletionList(ByVal prefixText As String, _ ByVal count As Integer) As String() Dim strCn As String = ConfigurationManager.ConnectionStrings("String").ToString() cn.ConnectionString = strCn Dim cmd As New SqlClient.SqlCommand cmd.Connection = cn cmd.CommandType = CommandType.Text cmd.CommandText = "SELECT Email, Name FROM List WHERE Email LIKE @myVariable AND UserName = @UserName" cmd.Parameters.AddWithValue("@myVariable", "%" + prefixText + "%") cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.User.Identity.Name).Value = HttpContext.Current.User.Identity.Name Try cn.Open() cmd.ExecuteNonQuery() Dim da As New SqlDataAdapter(cmd) da.Fill(ds) Catch ex As Exception Finally cn.Close() End Try dt = ds.Tables(0) 'Then return List of string(txtItems) as result Dim txtItems As New List(Of String) Dim dbValues As String Dim dbValues2 As String For Each row As DataRow In dt.Rows ''String From DataBase(dbValues) dbValues = row("Email").ToString() dbValues = dbValues.ToLower() ''String From DataBase(dbValues) dbValues2 = row("Name").ToString() dbValues2 = dbValues2.ToLower() txtItems.Add("<b>" + dbValues2 + "</b><br />") txtItems.Add(" " + dbValues) Next Return txtItems.ToArray() End FunctionRameshRajend...
Star
7983 Points
2099 Posts
Re: Email address comma seperaters
Dec 11, 2012 02:24 PM|LINK
Create New thread..........