I am new to JSON . I created a sample that returns a String from WebMethod and assigns the value returned to the asp.net Label control.
JSON String Return Example:
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "JSONSample.aspx/DisplayData", data: "{}", dataType: "json", success: function(data) { </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <label id="lbltxt" runat="server"></label> </asp:Content>
In the .cs file (return line):
[WebMethod] public static string DisplayData() { return DateTime.Now.ToString(); }
This works great.
How to access DataTable using JSON and JQuery ?
[WebMethod] public static DataTable DisplayData() { DataTable dt = new DataTable(); return dt.GetData(); }
I want to return a DataTable and bind GridView / Access to each row of the DataTable using JSON and JQuery . Please suggest me the correct Return DataTable method using JSON .
I saw some examples using handlers and some examples using WebMethod . Which one to use?
What are the advantages of one over the other.
Help rate!
source share