Sending objects between client and server

objects between client and server using .net

Sending objects between client and server

Below are Client side methods using ajax post.
add any page like test.aspx and add below code.

function ExportSetting() {
try {
debugger;
var objRequest = {};
objRequest.Id = “1001”;
objRequest.Name = “test”;
$.ajax({
type: “POST”,
url: “http://localhost:59948/WebForm1.aspx” + “/ExportData”,
data: “{objRequest:” + JSON.stringify(objRequest) + “}”,
contentType: “application/json; charset=utf-8”,
dataType: “json”,
success: function (data1, status) {
debugger;
var sfileName = data1.d;
if (emailOrExport == ’email’) {
toastr.success(“Exported report has been sent to your Email Id.”);
}
else {
}
},
error: function (request, status, error) {
debugger;
}
});
}
catch (e) {
}
}

2). Add test.cs page and add below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace test
{
public partial class test: System.Web.UI.Page
{
public class Employee
{
public string _Id { get; set; }
public string _Name { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod]
public static string GetvalefromClientSidetoServerSide(Employee objRequest)
{
string Id = objRequest._Id;
string Name = objRequest._Name;
return Id + Name;
}
}
}

u will get all the data in objRequest in C# side.  try it and reply.

 

Sending objects between client and server
Sending objects between client and server

for reference :  Sending objects between client and server

Split datatable into multiple tables

 

SHARE THIS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.