Hi,
Passing the DataTable from javaScript to C# is
pretty simple by using AjaxPro.dll. Here I code you by using Ajax webmethod
that transform the data faster than usual. Before placing the code add the
AjaxPro.dll to the Solution and call in the namespace section.
![]() |
Passing DataTable from Javascript to C# |
Aspx Code :
<html >
<head runat="server">
<title>Pass Datatable from Javascript to C# in Ajax Method </title>
<script type="text/javascript">
function ScheduleUpdn()
{
var dt = new Ajax.Web.DataTable();
dt.addColumn("SLNo", "System.String");
dt.addColumn("Location", "System.String");
dt.addColumn("TeamLead", "System.String");
dt.addColumn("Schedule", "System.String");
dt.addColumn("StartDate", "System.String");
dt.addColumn("EndDate", "System.String");
var row = new Object();
row.SLNo = "1";
row.Location = "T Nagar";
row.TeamLead = "Karthick";
row.Schedule = "meeting";
row.StartDate = "20-07-2015";
row.EndDate = "21-07-2015";
dt.addRow(row);
var returnmessage = MyAPP.WebForm1.SendCuurentRowUpdn(dt);
alert(returnmessage.value);
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btnajaxpro" value="Click to Pass
DataTable from JS to C#" onclick="return ScheduleUpdn();" />
</div>
</form>
</body>
</html>
C# Code:
using System;
using System.Web.UI.WebControls;
using AjaxPro;
using System.Data;
namespace MyAPP
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));
}
[AjaxPro.AjaxMethod]
public string SendCuurentRowUpdn(DataTable dtschdeduleupdn)
{
string ReturnString = "Datatable
Successfully Received";
try
{
return ReturnString;
}
catch (Exception ex)
{
throw ex;
}
}
}
}
Add the below code in web.config after completion of system.web
<location path="ajaxpro">
<system.webServer>
<handlers>
<add name="AjaxPro" verb="GET,POST" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro" />
</handlers>
</system.webServer>
</location>