I have an autocompleate extender on textbox which shows records as a list from database but whern I click on texbox and start typing nothing happned. my html code is
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
Enabled="True" TargetControlID="TextBox1" ServicePath="~/WebService.asmx"
ServiceMethod="GetCompletionList"
MinimumPrefixLength="2"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="20"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true" >
</asp:AutoCompleteExtender>
And my web service is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[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 WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public static List<string> GetCompletionList(string prefixText, int count)
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["cn"]);
if (con.State == ConnectionState.Closed)
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT gotra FROM tbgotra WHERE gotra LIKE '%" + prefixText + "%'",con);
List<string> k = new List<string>();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
k.Add(sdr["gotra"].ToString());
}
}
con.Close();
return k;
}
}
Try adding this line, i remember i had the same problem once where it worked for me locally but not live.
[WebMethod]
[System.Web.Script.Services.ScriptMethod] <-- Add this line
public static List<string> GetCompletionList(string prefixText, int count)
....
you Should to use
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
in before the TextBox1
try this signature for web method:
public string[] GetCompletionList(string prefixText, int count, string contextKey)
I think extender wont accept any other return type besides string[]
In my case, I had to un-comment this line in the ASMX file
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
In my case it was issue with the css class below, I've had it in the source but without z-index property.
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server"
ClientIDMode="Static" MinimumPrefixLength="1" ServiceMethod="GetAllStaff"
TargetControlID="txtTeacherName" ServicePath="~/webservices/WebService.asmx"
CompletionInterval="50" EnableCaching="true" CompletionSetCount="20"
ShowOnlyCurrentWordInCompletionListItem="true"
CompletionListCssClass="CompletionListCssClass">
</ajaxToolkit:AutoCompleteExtender>
<style>
.CompletionListCssClass {
font-size: 12px;
color: #000;
padding: 3px 5px;
border: 1px solid #999;
background: #fff;
width: 300px;
float: left;
position: absolute;
margin-left: 0;
overflow: auto;
height: 200px;
cursor: pointer;
z-index: 10000001 !important;
}
</style>
Related
i have this method in mail.cs file which take one parameter,call store procedures and and return values from database.
public void select(string type)
{
string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("EmailSetup_CRUD"))
{
cmd.Parameters.AddWithValue("#Action", "SELECT");
cmd.Parameters.AddWithValue("#Type", type);
}
}
}
i want to call the return values from this method on page behind and bind it with label. please advice how to do it.
on my page behind on page load i have done like this
mail callmail = new mail()
now i label1.text how to assign return value to label1.text.
method returns 5 column and i have 5 label on my page so each column will assign to each label.
As per the discussion and assumptions I made following code
mail.cs
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace tempApp4
{
public class mail
{
public DataTable select(string type)
{
string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("EmailSetup_CRUD", con))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#Action", "SELECT");
cmd.Parameters.AddWithValue("#Type", type);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
return dataSet.Tables[0];
}
}
}
}
}
WebForm1.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="tempApp4.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="label1" runat="server" />
<asp:Label ID="label2" runat="server" />
<asp:Label ID="label3" runat="server" />
<asp:Label ID="label4" runat="server" />
<asp:Label ID="label5" runat="server" />
</form>
</body>
</html>
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace tempApp4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
mail mail = new mail();
var table = mail.select("TYPE_VALUE");
label1.Text = Convert.ToString(table.Rows[0][0]);
label2.Text = Convert.ToString(table.Rows[0][1]);
label3.Text = Convert.ToString(table.Rows[0][2]);
label4.Text = Convert.ToString(table.Rows[0][3]);
label5.Text = Convert.ToString(table.Rows[0][4]);
}
}
}
SqlDataAdapter "adapter" used to fetch records from the DB and fill it in dataSet. Data set holds many table as your procedure returns single table the "select" method returns single table at the end as:
return dataSet.Tables[0];
Thus "select" method have return type as "DataTable". Then finally access returned value in code behind using mail class's object and filling the labels by accessing the column as follows:
label1.Text = Convert.ToString(table.Rows[0][0]);
The first 0 in "table.Rows[0][0]" is for rows and second is for column. For column optionally you can specify name of the column as:
label1.Text = Convert.ToString(table.Rows[0]["COLUMN_NAME"]);
Since I don't know the column names I am using indexing.
Hope it helps
Need to bind drop down value from another drop down value, web methods not
firing even after added web reference, not showing any error.
I am getting error *method 500.
I am using visual studio and I have asp.net application as one project and a web service as another project.I am using web service in my asp.net application.
There is some sort of problem im my web service code. But i am unable to debug continuosly from asp.net application to web service.
I put break point both in application and web service but break point not activated in web service and it shows me connection error.
How can i do this while hosting on localhost?
my country.aspx code
<form id="form1" runat="server">
<ajax:ToolkitScriptManager EnablePageMethods="true" ID="tsmcascading" runat="server">
</ajax:ToolkitScriptManager>
<div>
<div>
<asp:DropDownList ID="ddlstate" runat="server" AutoPostBack="true">
</asp:DropDownList>
<ajax:CascadingDropDown ID="cddstate" runat="server" ServicePath="~/cascadingdropdown.asmx"
Category="stateid" ServiceMethod="addstate" TargetControlID="ddlstate" PromptText="select state"
LoadingText="Loading...">
</ajax:CascadingDropDown>
</div>
</div>
<div>
<div>
<asp:DropDownList ID="ddlcity" runat="server">
</asp:DropDownList>
<ajax:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlcity"
Category="stateid" ParentControlID="ddlstate" ServiceMethod="addcity" PromptText="select city"
ServicePath="~/cascadingdropdown.asmx" LoadingText="Loading...">
</ajax:CascadingDropDown>
</div>
</div>
</form>
my webservice code (.asmx)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AjaxControlToolkit;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Specialized;
/// <summary>
/// Summary description for cascadingdropdown
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
// 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 cascadingdropdown : System.Web.Services.WebService
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["addcontact"].ToString());
public cascadingdropdown()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public CascadingDropDownNameValue[] addstate(string state, string city)
{
con.Open();
SqlCommand cmdstate = new SqlCommand("select stateid,statename from tblStates", con);
cmdstate.ExecuteNonQuery();
SqlDataAdapter dastate = new SqlDataAdapter(cmdstate);
DataSet dsstate = new DataSet();
dastate.Fill(dsstate);
con.Close();
List<CascadingDropDownNameValue> statesnames = new List<CascadingDropDownNameValue>();
foreach (DataRow dtrow in dsstate.Tables[0].Rows)
{
string stateid = dtrow["stateid"].ToString();
string statename = dtrow["statename"].ToString();
statesnames.Add(new CascadingDropDownNameValue(statename, stateid));
}
return statesnames.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] addcity(string state, string city)
{
int stateid;
StringDictionary statedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(state);
stateid = Convert.ToInt32(statedetails["state"]);
con.Open();
SqlCommand cmdcity = new SqlCommand("select cityid,stateid,cityname from tblcities where stateid=#stateid", con);
cmdcity.Parameters.AddWithValue("#stateid", stateid);
cmdcity.ExecuteNonQuery();
SqlDataAdapter dacity = new SqlDataAdapter(cmdcity);
DataSet dscity = new DataSet();
dacity.Fill(dscity);
con.Close();
List<CascadingDropDownNameValue> citynames = new List<CascadingDropDownNameValue>();
foreach (DataRow dtrow in dscity.Tables[0].Rows)
{
string cityid = dtrow["cityid"].ToString();
string cityname = dtrow["cityname"].ToString();
citynames.Add(new CascadingDropDownNameValue(cityid, cityname));
}
return citynames.ToArray();
}
}`
Try using the standard definition for functions used by AjaxControltoolkit cascading dropdown:
public CascadingDropDownNameValue[] addState(String knownCategoryValues, String category, String contextKey)
{
...
}
public CascadingDropDownNameValue[] addCity(String knownCategoryValues, String category, String contextKey)
{
...
}
Context key is not a mandatory parameter, you can ommit it if you do not need it.
I have totally the same problem, i found a "tutorial" and i tried to fit it with my own code, but i couldn't get it to work i was also getting method 500 errors.
Try use 100% of this websites code
http://www.aspdotnet-suresh.com/2011/01/introduction-here-i-will-explain-how-to.html
It worked for me, i just fitted some of the code at a time.
I have created a Custom Control with textbox.
I am calling it in GridView. When an Update event is fired it always saves 0.
I have used following code , could any one help in the same.
Following is the code used for custom control.
ASCX Code
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ItemRequiredTextBox.ascx.cs"
Inherits="ItemRequiredTextBox" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:TextBox ID="txtWin_Delievered_Qty" runat="server" >
<asp:FilteredTextBoxExtender ID="ftbe3" runat="server" TargetControlID="txtWin_Delievered_Qty"
ValidChars="1234567890" />
<asp:CompareValidator ID="CompareValidator1" runat="server" Display="None" ValueToCompare='<%# this.Text2 %>' ControlToValidate="txtWin_Delievered_Qty" Type="Integer"
ErrorMessage="Quantity to be delievered can not be More than Required Quantity"
Operator="LessThanEqual">
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" TargetControlID="CompareValidator1"
runat="server">
<asp:CompareValidator ID="CompareValidator2" runat="server" Display="None" ValueToCompare='<%# this.Text1 %>' ControlToValidate="txtWin_Delievered_Qty" Type="Integer"
ErrorMessage="Quantity delievered can not be less than delievered Quantity" Operator="GreaterThanEqual">
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" TargetControlID="CompareValidator2"
runat="server">
ASCX.CS Code
using System;
using System.Data;
using System.ComponentModel;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ItemRequiredTextBox : System.Web.UI.UserControl
{
[Bindable(true, BindingDirection.TwoWay)]
protected void Page_Load(object sender, EventArgs e)
{
}
private int TexT1;
private int TexT2;
public int Text1
{
get { return TexT1; }
set { TexT1 = value; }
}
public int Text2
{
get { return TexT2; }
set { TexT2 = value; }
}
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
}
Create a public property in the usercontrol to get textbox value:
public string Text
{
get
{
return txtWin_Delievered_Qty.Text;
}
}
And access the value in the gridview update event:
ItemRequiredTextBox irtBox = (ItemRequiredTextBox)gvMyGridView.Rows[e.Item.ItemIndex].FindControl("updatedBy");
string myText = irtBox.Text;
Here gvMyGridView is your gridview
I have a label within a <table> in a repeater. I have an HttpHandler named "NameShow.ashx" to return the "name" as "text/plain" by passing an "id" to the handler.
I want to retrieve the "name" (similar to retrieving "image" from handler).
Here is my code:
<asp:Label ID="Label1" runat="server" Text='<%#""NameShow.ashx?id="+Eval("id") %>'>
</asp:Label>
I am getting the text of this label as ->> NameShow.ashx?id=123
Please help in finding where I am doing mistake.
Here is my Haldler code.
using System;
using System.Web;
public class NameShow : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
string strid = context.Request.QueryString["id"];
long pro_id = int.Parse(strid);
string name = DBHelpername.name(pro_id);
context.Response.ContentType = "text/plain";
context.Response.Write(name);
}
public bool IsReusable {
get {
return false;
}
}
}
Here is my DBHelper code:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DBHelpername
/// </summary>
public class DBHelpername
{
public DBHelpername()
{
//
// TODO: Add constructor logic here
//
}
public static string name(long id)
{
SqlConnection connect = new SqlConnection
("Data Source=DELL-36B3EF6E9F;Integrated Security=True;Initial Catalog=pool");
connect.Open();
SqlCommand sc =
new SqlCommand("SELECT name FROM Profile WHERE profile_id=" + id + "", connect);
SqlDataAdapter da = new SqlDataAdapter(sc);
DataSet ds = new DataSet();
da.Fill(ds);
string nameret = ds.Tables[0].Rows[0][0].ToString();
return nameret;
connect.Close();
}
}
If you are not married to the idea of using an HTTP Handler, then I suggest making a method in your .aspx page's code-behind that does the same logic your handler is doing minus the content-type stuff, like this:
protected string GetName(int pro_id)
{
return DBHelpername.name(pro_id);
}
Now in your markup you can use this method, like this:
<asp:Label ID="Label1" runat="server" Text='<%# GetName((int)Eval("id")) %>'>
</asp:Label>
<%# new System.Net.WebClient().DownloadString("http://www.yoursite.com/NameShow.ashx?id="+Eval("id"))) %>
Something like this may work, although you might need to re-think your approach as you are going do a http request for each item in your repeater - and that isn't going to scale well! It looks like this is all in one application/website, so can you not call the code that looks up the name in the codebehind of this page?
I have a ajax autocomplete extender and everything works fine. I mean sql procedure and others are fine but when I enter something to textbox nothing happened.
Why is that?
Here is my codes.
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.Sql;
using System.Data.SqlClient;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[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 WebService : System.Web.Services.WebService {
string[] arr;
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] testing(string prefixText)
{
if (prefixText.Length > 0)
{
string sql = "Select * From titles Where title like #title";
SqlDataAdapter da = new SqlDataAdapter(sql, "myconnectionstring is here");
da.SelectCommand.Parameters.Add("#title", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["title"].ToString(), i);
i++;
}
return items;
}
arr[0] = "";
return arr;
}
}
Html side:
<%# Page Title="" Language="C#" MasterPageFile="~/adminpanel/adminpanel.master" AutoEventWireup="true" CodeFile="autocomplete.aspx.cs" Inherits="adminpanel_autocomplete" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
MinimumPrefixLength="1" ServiceMethod="testing" ServicePath="WebService.asmx" TargetControlID="TextBox1" Enabled="true">
</asp:AutoCompleteExtender>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
I wrote my jQuery AutoComplete handler.
So I fixed my question.
But still couldn't find the problem about ajax autocomplete extender.
Thanks.
You need to uncomment the following line from the webservice :
// [System.Web.Script.Services.ScriptService]