Return Array from Web Service using ScriptManager & Javascript

 This is used to call the Web Service using ASP.Net and Script Manager. Must be inserted in .aspx page. 

<asp:ScriptManager runat=”server” ID=”scriptManager”>
<asp:ServiceReference path=”WebService/TestService.asmx” />



This is the script to call the web service method and print the result on the form:

<script type=”text/javascript”>
        var res1=0;
        var res2=0;
        function initialize() {
        function OnSucceed(result) {
        function LoadById(id) {
            TestService.GetResult(id, OnSucceed);
        function LoadByDetail(testId) {
            TestService.GetResultByDetail(testId, OnSucceed);

Next is the Web Service “TestService”:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = ““)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
public class SearchMap : System.Web.Services.WebService
    public object[] GetResult(string id)
        //get two results from database using id
        object[] results = { row[0], row[1] };
        return results;

    public object[] GetResultByDetail(string testId)
        //get two results from database using test id
        object[] results = { row[0], row[1] };
        return results;



No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *