asp.net client / server

0

How could I call a server-side function from the client side, which returned results and use that data from the client side?

client-side code:

html:

<input type="button" value="Search" onclick="codeAddress();"</input>

javascript:

function codeAddress() {
    var variable1 = "medicina"
   //llamo a la funcion GetData //
   //guardo variables cada campo que devuelve la funcion GetData
   //...sigo con el codigo
   }

server-side code:

Private Function GetData(variable1 As String) As DataTable
Dim conString As String =ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim cmd As New SqlCommand("select * from location where especialidad =@variable1)
        Using con As New SqlConnection(conString)
            Using sda As New SqlDataAdapter()
                cmd.Connection = con

                sda.SelectCommand = cmd
                Using dt As New DataTable()
                    sda.Fill(dt)
                    Return dt
                End Using
            End Using
        End Using
    End Function
    
asked by user6905478 20.06.2018 в 00:54
source

1 answer

0

You could create in the codebehind of the aspx a WebMethod that returns the data that you need and from the part of the client, through Ajax, call this webmethod.

Subsequently, once the data has been recovered by Ajax, you use it as you see fit from the client side.

    
answered by 21.12.2018 в 10:33