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>
3 Comments
I am really Thankful for your blog post. I got too much interesting information.Keep up the good work.
ReplyDeleteMinnesota Website Design
Rochester web design
Outstanding blog with lots of information. Keep posting more like this.
ReplyDeleteccna course in Chennai
ccna institute in Chennai
ccna Training center in Chennai
gst classes in Chennai
ReactJS Training in Chennai
Salesforce Training in Chennai
ccna course in Tambaram
ccna course in Velachery
CCNA course in Vadapalani
Great Article android based projects
ReplyDeleteJava Training in Chennai Project Center in Chennai Java Training in Chennai projects for cse The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai