I am using autocomplete extender, i write a webservice the webse开发者_开发知识库rvice is working fine when i run webservice. But when i run my aspx page it is not displaying any thing the autocomplete is not showing only text box is there. this is my code......
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
SqlConnection con;SqlDataAdapter da;
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetTitleInfo(string prefixText)
{
int count = 10;
string sqry = "select * from news_upload where newstitle like @prefixText";
da = new SqlDataAdapter(sqry, "server=localhost;database=tfcnew;user id=sa;password=sql123");
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 100).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["newstitle"].ToString (), i);
i++;
}
return items;
}
this is (above) service.
<asp:TextBox ID="txtcomplete" runat ="Server" ></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" MinimumPrefixLength ="1" ServiceMethod ="GetSuggestions" ServicePath="~/WebService2.asmx" TargetControlID ="txtcomplete" >
</asp:AutoCompleteExtender>
This is aspx code..
can u help me. thank you.
Add "[System.Web.Script.Services.ScriptMethod]" before the class declaration
[System.Web.WebService(Namespace = "http://tempuri.org/")]
[System.Web.WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptMethod]
public class WebService : System.Web.Services.WebService {
...
...
...
if it is already in your code, You could check the service path. Use Fiddler or Firebug to see if there is an actual call to the service. if not working then set the servicepath from paga_Load event of your aspx page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack() Then
AutoCompleteExtender2.ServicePath = ResolveUrl("~/mywebservice.asmx")
End If
End Sub
精彩评论