1

I am trying to load my dynamically generated Datatable during runtime into JS array in javascript. But cannot pass it through webservice as only static methods can be called through javascript.How to return the datatable into javascript.

aspx.cs file :

protected void btnRead_Click(object sender, EventArgs e)
{
//on button click it reads file path of excel and stores it in a string path 
}

private DataTable ReadExcelWithStream(string path)

{
//method reads the excel file and stores it in a dt
ForJs(dt);
     return dt;
 }
[ScriptMethod, WebMethod]
 public static DataTable ForJs(DataTable dt)
 {

     return dt;
 }

aspx file :

 <script type="text/javascript">
        function InsertLabelData() {
           PageMethods.ForJs(onSuccess, onFailure);

        }

             function onSuccess(dt) {

    //attach the table to dhtmlx grid
    }

But the datatable is not passed to the javascript. How to pass the datatable to javascript from c# ? or any other methods to pass the datatable from c# to JS

Please Help.

Thanks!

SabareeshSS
  • 1,361
  • 2
  • 11
  • 20

1 Answers1

0

duplicate?/related question: Dynamically pass datatable from C# to Javascript

You can not simply pass an(y) object to JavaScript. It has to be in a usable format. Like an array or serialized to XML or JSON. Also "DataTables contain lots of additional information which JSON cannot store".

Take a look at how to pass c# datatable to a javascript function or What's the best way to jSON serialize a .NET DataTable in WCF? for more information on this subject.

Community
  • 1
  • 1
Doku-so
  • 346
  • 3
  • 9