I am trying to Create a google like search box.I am not getting any result of this. Am just trying to make the auto complete feature for now the search thing is not yet done .Below is what i have tried.
<====== Directory.aspx file =======>
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<div class="search-box">
<span class="strong">Search Members: </span>
<ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="2"
TargetControlID="myTextBox"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="100"
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>
</ajaxToolkit:AutoCompleteExtender>
<asp:TextBox ID="myTextBox" AutoCompleteType="FirstName" placeholder="Type First Name Here" runat="server"></asp:TextBox>
</div>
And the AutoComplete.asmx.cs file
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
// All other rights reserved.
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
///<summary>
/// Summary description for AutoComplete
///</summary>
[WebService(Namespace = "localhost")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
// uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
public AutoComplete()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
//ADO.Net
MySqlConnection cn = new MySqlConnection("Database=bvshree;Data Source=localhost;User Id=root;Password=axcva4###3");
DataSet ds = new DataSet();
DataTable dt = new DataTable();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandType = CommandType.Text;
//Compare String From Textbox(prefixText) AND String From
//Column in DataBase(CompanyName)
//If String from DataBase is equal to String from TextBox(prefixText)
//then add it to return ItemList
//-----I defined a parameter instead of passing value directly to
//prevent SQL injection--------//
cmd.CommandText = "select * from family_header Where Self_Name like #myParameter";
cmd.Parameters.AddWithValue("#myParameter", "%" + prefixText + "%");
cn.Open();
cmd.ExecuteNonQuery();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(ds);
cn.Close();
dt = ds.Tables[0];
//Then return List of string(txtItems) as result
List<string> txtItems = new List<string>();
String dbValues;
foreach (DataRow row in dt.Rows)
{
//String From DataBase(dbValues)
dbValues = row["Self_Name"].ToString();
dbValues = dbValues.ToLower();
txtItems.Add(dbValues);
}
return txtItems.ToArray();
}
}
I saw this question again after long time, since none posted any reply I thought I should myself reply to it.
The Problem was with the styling of the code the opacity of the list being generated was set to zero and was not changing as expected. So I just removed to animation from it to get the solution. :)
Related
hi I am trying to make a log in page as well as sign up page in asp.net using 3 tier architecture by using sql server architecture. I am able to fetch data from sql server data base which I have manually inserted during table creation in database and I am able to use it in my log in page.
I have also created a sign up page but I am not able to get the values from sign up webform textbox to sqlserver database I am getting some error kindly help me with this.
I have given the connection string of sql server in web.config
my sql server table creation code
CREATE TABLE LOGINDETAILS
(USERID VARCHAR(50),
PASSWORD VARCHAR (50)
);
INSERT INTO LOGINDETAILS (USERID,PASSWORD) values( 'sam', 'pass');
web.config connection string code
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="DBcon" connectionString="Data Source=P3A-B1YH882\SQLSERVER;Initial Catalog=master;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
my business layer /middle layer code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using DataAcess;
using System.Data.SqlClient;
using System.Data.Sql;
namespace middlelayer
{
public class UserBO
{
private string _UserName = " ";
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
private string _Password = " ";
public string Password
{
get { return _Password; }
set { _Password = value; }
}
DataA da = new DataA();
public bool getUser()
{
if (da.IsValid(UserName, Password).Tables[0].Rows.Count == 0)
{
return false;
}
else
{
return true;
}
}
}
}
my datAccess layer code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
namespace DataAcess
{
public class DataA
{
string conString = ConfigurationManager.ConnectionStrings["DBcon"].ToString();
public DataSet IsValid(string UserName, string Password)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM LOGINDETAILS WHERE USERID ='" + UserName + "' and PASSWORD= '" + Password + "'", con);
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
return ds;
}
}
}
MY LOGIN PAGE CODE
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="WebApplication4.login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="height: 277px">
<form id="form1" runat="server">
<div>
<asp:Label ID="lbluserid" runat="server" BackColor="#FFFF99" BorderStyle="Ridge" Height="17px" Text="User ID" Width="52px"></asp:Label>
<asp:TextBox ID="txtuserid" runat="server" BackColor="#99FFCC" style="margin-left: 122px"></asp:TextBox>
<br />
</div>
<p>
<asp:Label ID="lblpassword" runat="server" BackColor="#FFFF99" BorderStyle="Ridge" Text="Password"></asp:Label>
<asp:TextBox ID="txtpassword" TextMode="Password" runat="server" BackColor="#99FFCC" style="margin-left: 110px" ></asp:TextBox>
</p>
<p>
</p>
<asp:Button ID="btnlogin" runat="server" BackColor="#33CCFF" BorderStyle="Ridge" OnClick="btnlogin_Click" style="margin-left: 78px" Text="Login" Width="107px" />
<p>
</p>
<asp:Label ID="Label1" runat="server" Text="NOT REGISTERED ??"></asp:Label>
<asp:HyperLink ID="HyperLink1" runat="server" BorderStyle="Outset" NavigateUrl="~/sign_up.aspx">SIGN UP</asp:HyperLink>
</form>
</body>
</html>
* MY SIGN UP PAGE CODE*
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="sign_up.aspx.cs" Inherits="WebApplication4.sign_up" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="lblssignup" runat="server" BackColor="#FF99CC" Text="SIGN UP"></asp:Label>
<br />
<br />
<p>
<asp:Label ID="lblsuserid" runat="server" Text="ENTER USER ID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" style="margin-bottom: 0px"></asp:TextBox>
</p>
<asp:Label ID="lblspassword" runat="server" Text="ENTER PASSWORD"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<p>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" Width="66px" />
</p>
</form>
</body>
</html>
SIGN UP PAGE BUTTON CODE FOR ENTERING DATA INTO SQL SERVER DATABASE ON BUTTON CLICK
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using middlelayer;
namespace WebApplication4
{
public partial class sign_up : System.Web.UI.Page
{
string conString = ConfigurationManager.ConnectionStrings["DBcon"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
string ins= "Insert into [LOGINDETAILS](USERID, PASSWORD) VALUES ('" +TextBox1.Text+ "' , '" +TextBox2.Text+ "')";
SqlCommand com = new SqlCommand(ins,con);
DataSet du = new DataSet();
SqlDataAdapter sdi = new SqlDataAdapter(com);
sdi.Fill(du);
con.Close();
}
}
}
I AM getting error in this last code only of sign up button it is not able to insert values of SIGN UP webform Textbox to sql server databse table and also not reflecting the real values which I want to add in sql server TABLE using sign up webform and also noty saving it. It is sending some error values . kindly help me with this.
BELOW ARE THE IMAGES OF LOG IN AS WELL AS SIGN UP PAGE FOR REFERENCE
LOGIN PAGE WEB FORM
SIGN UP PAGE WEBFORM
KINDLY HELP IN RESOLVING THIS ISSUE
Try this:
SqlConnection con = new SqlConnection(conString);
con.Open();
string ins= "Insert into [LOGINDETAILS](USERID, PASSWORD) VALUES (#param1 , #param2)";
SqlCommand cmd = new SqlCommand(ins,con);
cmd.Parameters.Add("#param1", SqlDbType.Varchar, 50).value = TextBox1.Text;
cmd.Parameters.Add("#param2", SqlDbType.Varchar, 50).value = TextBox2.Text;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
con.Close()
I am trying to implement a search textbox with the Ajax Control Toolkit AutoCompleteExtender. The result should be a list of names matching the entered text however what gets displayed is the page source HTML, character by character, creating an extremely long list of single letters.
I have found and tried several samples but cannot get this to work. I am certain the database connection is valid and the SQL query when executed directly in MSSMS, returns the expected result. The AjaxControlToolkit is installed and works on other pages in the solution.
This issue was asked before ("Ajax Control Toolkit AutoCompleteExtender displays html source character by character of the current page as autocomplete suggestion list"). However for reasons of simplicity and maintainability I do not want to implement a WebService as this poster did.
acex.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AutoCompleteExtender - Last Names</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:TextBox ID="txbxLastName" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
TargetControlID="txbxLastName"
MinimumPrefixLength="2"
EnableCaching="true"
CompletionSetCount="1"
CompletionInterval="1000"
ServiceMethod="GetLastNames">
</asp:AutoCompleteExtender>
</div>
</form>
</body>
</html>
acex.aspx.cs
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace MCA
{
public partial class acex : System.Web.UI.Page
{
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetLastNames(string prefixText)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString());
SqlCommand cmd = new SqlCommand("SELECT [Last_Name] FROM [Entity_Person] WHERE [Last_Name] LIKE #Name+'%'", conn);
cmd.Parameters.AddWithValue("#Name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
conn.Open();
da.Fill(dt);
List<string> LastNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
LastNames.Add(dt.Rows[i][0].ToString());
}
return LastNames;
}
}
}
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
object User = Session["$UserName"];
if (User != null)
{
pnlLogin.Visible = false;
pnlWelcome.Visible = true;
lblUserName.Text = User.ToString();
}
else
{
pnlWelcome.Visible = false;
pnlLogin.Visible = true;
}
`protected void btnlogin_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings[0].ConnectionString);
string sorgu = "SELECT * FROM TB_User WHERE StrUserID = #UserName AND password = #Password";
string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5");
SqlCommand cmd = new SqlCommand(sorgu, cnn);
cmd.Parameters.AddWithValue("#UserName", txtUserName);
cmd.Parameters.AddWithValue("#Password", hashedPassword);
cnn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session.Add("User", dr["StrUserID"].ToString());
Response.Redirect(Request.RawUrl);
}
else
{
lblresult.Text = "Login Failed";
}
cnn.Close();`
}
}
here asp & html codes
<div class="login">
<asp:Panel ID="pnlLogin" runat="server">
<div class="loghead">
LOGIN
</div>
<div class="logfoot">
<span>ID</span>
<br />
<asp:TextBox ID="txtUserName" CssClass="TextBox" runat="server" Width="151px" Height="21px" />
<br />
<span>Password</span>
<br />
<asp:TextBox ID="txtPassword" CssClass="TextBox" TextMode="Password" runat="server" Height="21px" Width="151px" />
<br />
<asp:Button ID="btnregister" CssClass="btnregister" Text="REGISTER" runat="server" OnClick="btnregpag_Click" />
<asp:Button ID="btnlogin" CssClass="btnlogin" Text="LOGIN" runat="server" OnClick="btnlogin_Click" />
<asp:Label ID="lblresult" Text="" runat="server" />
</div>
</asp:Panel>
<asp:Panel ID="pnlWelcome" runat="server"> Welcome ,<asp:Label ID="lblUserName" Text="" runat="server" /> </asp:Panel>
</div>
Thats my code for login, database passwords crypto with md5.
When i try login i got error at visual studio 2015
thats error :ERROR IMAGE HERE
Whats wrong here?
And sql table :SQL TABLE HERE
i find whats wrong
txtusername after.text
cmd.Parameters.AddWithValue("#UserName", txtUserName.text);
Now login event working
First of all there is a code syntax error in your code as mentioned in my latest comment.
Also, for md5 password storing you need to know something like
The output of any hash function is a collection of bytes, not a collection of text. So when you enter text as a test you are probably entering a text conversion of that byte array. Simply converting it in SQL to a binary(16) is not correct, you need to do a proper conversion, which is something you cannot do in SQL. This also explains why changing the datatype of the column doesn't work either. Taken from here
I am presenting a small piece of code which might help you in achieving your current task.
Here you go:-
On button click
//get the username
string UserName = txtUserName.Text;
//create the MD5CryptoServiceProvider object we will use to encrypt the password
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
//create an array of bytes we will use to store the encrypted password
Byte[] hashedBytes;
//Create a UTF8Encoding object we will use to convert our password string to a byte array
UTF8Encoding encoder = new UTF8Encoding();
//encrypt the password and store it in the hashedBytes byte array
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(txtPassword.Text));
Don't forget to add the related namespace for the hashing. Have a look below
using System.Security.Cryptography
For full reference you may have look at Using MD5 to Encrypt Password
Take a new aspx page and step into the documentation which I provided you as above.
That will surely help you to achieve your requirement.
Hope that helps.
I have two text boxes that should be getting filled with Ajax AutoCompleteExtender information. One text done with a Web Service and the other is a code behind Web Method. The Web Service one is for Customer IDs; If I start my page with the web service and put in a number for the ID it works and gives me all of the information but if I try to do it in my actual asp.net form then nothing happens when I type in a number to for my search criteria. Also, for the Web Method from the code behind doesn't seem to find anything for me when I type a letter...... I'm wondering if I am missing a reference or something that is making my actual web page not fetch the data or am I just doing it wrong as this is my first time using this.
I am using Visual Studio 2012
asp.net webform
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Orders.aspx.cs" Inherits="TropicalServer.UI.Orders" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link type="text/css" rel="stylesheet" href="~/AppThemes/TropicalStyles/Orders.css" />
<title>Orders Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<!-- Criteria Bar -->
<div>
<table>
<tr>
<td>
<asp:Label ID="lblOrderDate" runat="server" Text="Order Date: "></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlOrderDate" runat="server"></asp:DropDownList>
</td>
<td>
<asp:Label ID="lblCustID" runat="server" Text="Customer ID: "></asp:Label>
</td>
<td>
<asp:TextBox ID="tbCustID" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="aceCustID" runat="server"
ServicePath="wsOrders.asmx"
TargetControlID="tbCustID"
MinimumPrefixLength="1"
CompletionInterval="100"
CompletionSetCount="1"
ServiceMethod="GetCustomerID"
UseContextKey="true"
EnableCaching="true"> </ajaxToolkit:AutoCompleteExtender>
</td>
<td>
<asp:Label ID="lblCustName" runat="server" Text="Customer Name: "></asp:Label>
</td>
<td>
<asp:TextBox ID="tbCustName" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="aceCustName" runat="server"
TargetControlID="tbCustName"
MinimumPrefixLength="1"
EnableCaching="true"
CompletionInterval="1000"
CompletionSetCount="1"
UseContextKey="True"
ServiceMethod="GetCustomerName">
</ajaxToolkit:AutoCompleteExtender>
</td>
<td>
<asp:Label ID="lblSalesManager" runat="server" Text="Sales Manager: "></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlSalesManager" runat="server"></asp:DropDownList>
</td>
</tr>
</table>
</div>
<!-- End Criteria -->
Code Behind asp.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using TropicalServer.DAL;
namespace TropicalServer.UI
{
public partial class Orders : System.Web.UI.Page
{
#region Declerations
DALConnection TropConnection;
#endregion
#region Constructor
public Orders()
{
TropConnection = new DALConnection();
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
}
#region WebMethod
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public List<string> GetCustomerName(string prefixText)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "spCustName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#CustName", prefixText);
cmd.Connection = TropConnection.GetConnection();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
List<string> CustomerNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CustomerNames.Add(dt.Rows[i]["CustName"].ToString());
}
return CustomerNames;
}
#endregion
}
}
Web Service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using TropicalServer.DAL;
namespace TropicalServer
{
/// <summary>
/// Summary description for wsOrders
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class wsOrders : System.Web.Services.WebService
{
#region Declerations
DALConnection TropConnection;
#endregion
#region Constructor
public wsOrders()
{
TropConnection = new DALConnection();
}
#endregion
//"SELECT * FROM tblOrder WHERE OrderCustomerNumber LIKE #CustID+'%'"
[WebMethod]
public List<string> GetCustomerID(string prefixText)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "spCustID";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#CustID", prefixText);
cmd.Connection = TropConnection.GetConnection();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
List<string> CustomerIDs = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CustomerIDs.Add(dt.Rows[i]["OrderCustomerNumber"].ToString());
}
return CustomerIDs;
}
}
}
WEB CONFIG
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="TropicalServerConnectionString" value="Initial Catalog=TropicalServer;Data Source=Nicolas-PC\SQLEXPRESS;Integrated Security=true;" />
</appSettings>
<connectionStrings>
<add name="TropicalServerConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=Nicolas-PC;Initial Catalog=TropicalServer;Integrated Security = true" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<authentication mode="Forms">
<!--<forms loginUrl="~/Account/Login.aspx" timeout="2880" />-->
</authentication>
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages></system.web>
</configuration>
I think your problem is with your method signature. If you have UseContextKey="True", the method should be:
public static string[] GetCustomerID(string prefixText, int count, string contextKey)
{
}
If UseContextKey="False", the method should be:
public static string[] GetCustomerID(string prefixText, int count)
{
}
I am using Asp.Net/C#,In one of my pages I am using Ajax autocompleteextender for auto suggestions , Following is the code I am using
<Services>
<asp:ServiceReference Path="AutoCompleteSearchByName.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<ajaxtoolkit:autocompleteextender runat="server" ID="autoComplete1"
TargetControlID="txtCountry" ServicePath="AutoCompleteSearchByName.asmx"
ServiceMethod="GetNames" MinimumPrefixLength="1" EnableCaching="true" />
However in the design mode it is giving me an error.The error says ,
Error creating control autocomplete1 , AutocompleteSearchByName.asmx could not be set on property ServicePath
Here is my AutoCompleteSearchByName.asmx code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace CwizBankApp
{
/// <summary>
/// Summary description for AutoCompleteSearchByName
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
//[System.Web.Script.Services.ScriptService]
public class AutoCompleteSearchByName : System.Web.Services.WebService
{
[WebMethod]
public string[] GetNames(string prefixText)
{
DataSet dst = new DataSet();
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["Server=Server;Database=CwizData;Trusted_Connection=True"]);
string strSql = "SELECT f_name FROM cust_master WHERE f_name LIKE '" + prefixText + "%' ";
SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);
sqlCon.Open();
SqlDataAdapter sqlAdpt = new SqlDataAdapter();
sqlAdpt.SelectCommand = sqlComd;
sqlAdpt.Fill(dst);
string[] cntName = new string[dst.Tables[0].Rows.Count];
int i = 0;
try
{
foreach (DataRow rdr in dst.Tables[0].Rows)
{
cntName.SetValue(rdr["f_name"].ToString(), i);
i++;
}
}
catch { }
finally
{
sqlCon.Close();
}
return cntName;
}
}
}
Can anybody suggest me how do I solve this issue.
Thanks
Check that you are using proper DLL for this and have look to below code aslo
IF it still not work check this article and by donlowding code check what mistake you done : AutoComplete With DataBase and AjaxControlToolkit
Try this :
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="2"
TargetControlID="myTextBox"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="1000"
CompletionSetCount="20"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
or
This not meet up with you answer but if you want you can also go for jquery soltuion here is full article for this : Cascading with jQuery AutoComplete