Hi sureshMGR,
Check this example. Now please take its reference and correct your code.
HTML
<asp:Button Text="Get Array" OnClick="GetArray" runat="server" /><hr />
<asp:GridView runat="server" ID="gvNames" />
Code
C#
protected void GetArray(object sender, EventArgs e)
{
string url = "http://localhost:7957/Return_Array_Handler/Handler.ashx";
string response = (new System.Net.WebClient()).DownloadString(url);
string[] names = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<string[]>(response);
gvNames.DataSource = names;
gvNames.DataBind();
}
VB.Net
Protected Sub GetArray(ByVal sender As Object, ByVal e As EventArgs)
Dim url As String = "http://localhost:7957/Return_Array_Handler/Handler.ashx"
Dim response As String = (New System.Net.WebClient()).DownloadString(url)
Dim names As String() = New System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(Of String())(response)
gvNames.DataSource = names
gvNames.DataBind()
End Sub
Handler
C#
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Web.Script.Serialization;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string[] nameArray = { "John Hammond", "Mudassar Khan", "Suzanne Mathews", "Robert Schidner" };
context.Response.ContentType = "text/plain";
JavaScriptSerializer js = new JavaScriptSerializer();
string json = js.Serialize(nameArray);
context.Response.Write(json);
}
public bool IsReusable
{
get
{
return false;
}
}
}
VB.Net
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
Imports System.Web
Imports System.Web.Script.Serialization
Public Class Handler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim nameArray As String() = {"John Hammond", "Mudassar Khan", "Suzanne Mathews", "Robert Schidner"}
context.Response.ContentType = "text/plain"
Dim js As JavaScriptSerializer = New JavaScriptSerializer()
Dim json As String = js.Serialize(nameArray)
context.Response.Write(json)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Screenshot