<div>
<asp:Button ID="btnGetMsg" runat="server" Text="Click Me" OnClientClick="DisplayMessageCall();return false;" /><br />
<asp:Label ID="lblOutput" runat="server" Text=""></asp:Label>
<table id="container">
<tr>
<th>MaterialName
</th>
<th>QuantityType
</th>
</tr>
</table>
<asp:DropDownList ID="ddlNo" runat="server" ></asp:DropDownList>
</div>
<script type="text/javascript">
function DisplayMessageCall() {
$.ajax({
url: "Handler.ashx",
data: "",
type: "GET",
datatype: 'json',
success: function (data) {
$("#container tr+tr").remove();
var table = $("#container");
var list = $("#ddlNo");
var listItems = "";
$(data).each(function (i) {
table.append($("<tr>").append($("<td>").html(data[i].MaterialName)).append($("<td>").html(data[i].QuantityType)));
listItems += "<option value='" + data[i].MaterialName + "'>" + data[i].QuantityType + "</option>";
}
);
$("#ddlNo").html(listItems);
},
error: OnErrorCall
});
}
function OnSuccessCall(response) {
$('#<%=lblOutput.ClientID%>').html(response);
}
function OnErrorCall(response) {
alert(response.status + " " + response.statusText);
}
$(function () {
$("#ddlNo").change(function () {
window.location = 'http://localhost:50689/testingwebservice/Default.aspx?id=' + this.value
$('#<%=lblOutput.ClientID%>').html(this.value);
});
});
</script>
using System.Collections.Generic;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "application/json";
string period = context.Request.QueryString["Period"];
List<MaterialEntity> objList = new List<MaterialEntity>();
for (int i = 0; i < 10; i++)
{
objList.Add(new MaterialEntity()
{
MaterialName = period + " " + i.ToString(),
QuantityType = period + " " + i.ToString()
});
}
System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
new System.Web.Script.Serialization.JavaScriptSerializer();
string sJSON = oSerializer.Serialize(objList);
context.Response.Write(sJSON);
}
public bool IsReusable {
get {
return false;
}
}
}
public class MaterialEntity
{
public string MaterialName { get; set; }
public string QuantityType { get; set; }
}