Recent Posts

Tuesday, September 22, 2009

How to use Json objects and Jqeury in Part -3

This is continuation of the tutorial how to use JSON objects and JQuery in part -2
which explains the aspx page and how to use JQuery to render the data into the aspx page. This part of the tutorial explains how to use a handler to communicate between the Java script and the business logic layer and return back the json objects data. If you want to go to the starting of this article then it can be found in How to use JSON objects and JQuery in part -1.

Lets add the handler in the Asp .net web project and name it jqAirlines.ashx.
My whole code for jqAirlines.ascx can be found here:

Now in sub ProcessRequest check the parameters received (action).

I have declared the business layer as bll and lstAir as list of my TarrifAirlines

and similarly set the contextType = "application/json" that means we will be returning json format data back

Similarly get the pageSize and startRecord and put them in variables.

Then it calls the function bll.CountAirlinesJQ that gives the count of the records and then calls the function bll.GetAirlinesJQ that gets the list of TariffAirlines which is explained in How to use Json objects and Jqeury in Part -1.

Now the lstAir is the list of TariffAirlines and we need to convert it to json format, so we can get stuck here and try to find the ways or even plan to write the function to convert it. It is a lengthy process so why not use opensource dll (Newtonsoft.Json.dll) by Newtonsoft which can be downloaded from Json.Net
strJsonAir = Newtonsoft.Json.JavaScriptConvert.SerializeObject(lstAir)

Now strJsonAir would have list of TariffAirlines as a serilized string in json format.

We now declare a stringBuilder named writer and lets append with count, pagesize, startRecord and data that contains the collection of TarrifAirlines ie strJsonAir in the JSON format and write it back which is then used by our javascript explained in How to use Json objects and Jqeury in Part -2

Now hope you understand the now how to use JQuery, and render the JSON objects in three tier ASP. net web applications. If any confusion or suggestions please feel free to comment or directly email me.

Related Posts by Categories

No comments:

Post a Comment