• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

ASP.NET AJAX callbacks to Web Methods in ASPX pages

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;
        }
    </script>

    <title></title>
    </head>
<body>

    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>
    <div>
    
     
                    
                    <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>
                    </td>
                  
        
    
    </div>
    </form>


Index.aspx.vb

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")
        ds.Fill(dts)
        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_from.Items.Add(dr("Name").ToString)me
                'Me.Ddl_from.Items.
                Me.Ddl_City.Items.Insert(dr("Id"), dr("Name").ToString)
            Next
        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
        ds.Fill(dts)
        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/>")
        Next
        Dim a As String = "Abhishek"
        Return a.ToString
    End Function
End Class

Open in new window

0
navinbabu
Asked:
navinbabu
1 Solution
 
amar31282Commented:
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...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now