Wednesday, April 11, 2007

Code for JSON DataSet Deserialization in

My typed DataSet looks like this:









This method is in code behind

[WebMethod]
public static MyDS GetDataFromServer()
{
MyDS d = new MyDS();
d.MyTable.AddMyTableRow("1", "abc");
return d;

}



The following lines are from aspx page accessing the service:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods=true>
<Services>
<asp:ServiceReference Path="Common\TestService.asmx" />
</Services>
</asp:ScriptManager>



Given below is the javascript code:

<script type="text/javascript" language="javascript">

function OnLookupComplete(result, userContext)
{
//Accessing typed dataset using column names
alert(result.tables[0].rows[0].ID);
alert(result.tables[0].rows[0].Name);
}

function OnError(result)
{
alert("Error: " + result.get_message());
}
function init()
{
debugger; //start debugging
TestService.GetDataFromServer(OnLookupComplete,OnError);
}

</script>


It is called on body.onload

<body onload="init();">

1 comment:

Nysa said...

Good for people to know.