ASP.NET AJAX callbacks to Web Methods in ASPX pages

Posted on 2010-01-08
Last Modified: 2012-06-27
Im tryng for auto complete I m including my code . Please check for errors .

Im able to trigger the javascript function but couldnt proceed further .
<script type="text/javascript" language="javascript">

        function getlist() {


            document.getElementById('values').innerHTML = "";

            PageMethods.returnList(document.getElementById('txtinput').value, CallSuccess, CallFailed)


        function CallSuccess(result) {

            document.getElementById('values').innerHTML = "";

            document.getElementById('values').innerHTML = result;


        function CallFailed(res, destCtrl) {

            document.getElementById('values').innerHTML = "";

            document.getElementById('values').innerHTML = res;


        function changetext(val) {

            document.getElementById('txtinput').value = val;

            document.getElementById('txtinput').select = true;






    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">






                    <asp:TextBox ID="txtinput" runat="server" Width="385px"></asp:TextBox>

                    <div style="clear:both;"></div>

            <div id="values"  style="position: absolute; z-index:100; vertical-align:top; width: 385px; max-height: 100px; overflow: auto; border: 1px solid #666;"></div>








Imports System.Web

Imports System.Web.Services

Imports System.Web.Services.Protocols

Imports System.Collections

Imports System.Collections.Generic

Imports System.Collections.Specialized

Imports AjaxControlToolkit

Imports System.Data

Imports System.Data.SqlClient

Imports System.Configuration

Imports System.Web.Script.Services

<System.Web.Script.Services.ScriptService()> _

Partial Class index

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.txtinput.Attributes.Add("onkeyup", "getlist();")

        Dim con As String = ConfigurationManager.ConnectionStrings("food").ConnectionString

        Dim ds As New SqlDataAdapter("SELECT [Name],[Id] FROM [City]", con)

        Dim dts As New DataSet

        Me.Ddl_City.Items.Add("Please Select")


        Dim count As Integer = dts.Tables(0).Rows.Count

        Dim items As Integer = Me.Ddl_City.Items.Count

        items = items - 1

        If items = 0 Then

            For Each dr As DataRow In dts.Tables(0).Rows



                Me.Ddl_City.Items.Insert(dr("Id"), dr("Name").ToString)


        End If

    End Sub

    <WebMethod()> _

           <ScriptMethod()> _

Public Shared Function returnList(ByVal Name As String) As String

        Dim con As String = ConfigurationManager.ConnectionStrings("food").ConnectionString

        Dim ds As New SqlDataAdapter("SELECT [Name],[Id] FROM [City] LIKE @Name", con)

        Dim dts As New DataSet

        Dim out As New StringBuilder


        For Each dr As DataRow In dts.Tables(0).Rows

            out.Append("<a style='cursor:pointer;text-decoration:none;' onmouseover='changetext(this.innerHTML)'>" + dr("Name") + "</a><br/>")


        Dim a As String = "Abhishek"

        Return a.ToString

    End Function

End Class

Open in new window

Question by:navinbabu
    1 Comment
    LVL 14

    Accepted Solution

    make sure that you are getting the ellement 'txtinput' inside the javascript ... what i doubt is this that u r should get the element like this document.getElementById(<%=txtinput.ClientID%>').value

    If not the issue then check if the control is going to codebehind file by putting one break inside the returnlist method.. if its returning value or not...

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now