How can i read Handsontable array in ASP.Net? - vb.net

I have an handsontable and i am trying to read the array data in ASP.Net. i have the below code. When i send the data to server. i keep getting ParseError. I tried different ways but did not help.
var data = [
["Year", "Kia", "Nissan", "Toyota", "Honda"],
["2008", 10, 11, 12, 13],
["2009", 20, 11, 14, 13],
["2010", 30, 15, 12, 13]
];
var $container = $("#example1");
$container.handsontable({
data: data
});
function sendData() {
var $container = $("#example1");
var handsontable = $container.data('handsontable');
var myData = handsontable.getData();
$.ajax({
type: "POST",
url: "Test.aspx/SaveUser",
data: "{'data':" + JSON.stringify(myData) + "}",
dataType: "json",
success: function (response) {
alert("Data sent to server.");
window.location.reload();
},
error: function (xhr, status) {
alert("An error occurred: " + status);
}
});
}
Server side code
<WebMethod()> <ScriptMethod()> _
Public Shared Sub SaveUser(data As List(Of String))
Dim lstItems As List(Of Object) = New JavaScriptSerializer().ConvertToType(Of List(Of Object))(data)
End Sub
Please help me in reading the data and thanks in advance

I figured it out. Hope it helps others
just changed the line
data: '{data: ' + JSON.stringify(myData) + '}',

Related

Uncaught TypeError: datapoints.data.map is not a function at XMLHttpRequest.xmlhttp.onreadystatechange

Can anyone help me? I'm really bad at programming
Error :Uncaught TypeError: datapoints.data.map is not a function at XMLHttpRequest.xmlhttp.onreadystatechange
const xmlhttp = new XMLHttpRequest();
const url = '//url//';
xmlhttp.open('GET', url, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
const datapoints = JSON.parse(this.responseText);
//console.log(datapoints);
const labelsboy = datapoints.data.map(function(item){
return item.boy;
});
console.log(labelsboy);
}
}
file JSON API
{
"status": true,
"row": 2,
"data": {
"boy": 10,
"girl": 15
}
}
map is an array function but datapoints.data is an object. It seems like you are just trying to get one value from the object so you can just access it directly.
const labelsboy = datapoints.data.boy;
console.log(labelsboy);

I am trying to get the value of a variable in javascript using webbrowser1 in vb 20017. I cannot get my browser to recognize the function

JS function:
(function () {
//fix to dismiss tooltips of iOS Safari
if ('ontouchstart' in document.documentElement) {
$('body').css('cursor', 'pointer');
}
})();
function getOrderProgressBar(orderNumber) {
$('#order-status-container').hide();
$.ajax({
url: '/GetOrderProgressBar',
type: "POST",
data: {
orderNumber: orderNumber
},
success: function (data) {
if (data.Success) {
var activeStepTitle = "";
var stepsFraction = "";
$(".order-progress-bar-container").empty();
var html = '<div class="order-progress-bar" data-current-step-index="' + data.CurrentActiveStepIndex + '" data-current-step-description="' + data.CurrentActiveStepDesctiption + '">';
I am needing to get the value of the last line "data.CurrentActiveStepDescription" I have tried several different ways to put the value out but cannot get the program to recognize the function.
Any help is greatly appreciated!! Thank you

Cannot load more than 2 files to S3 using plupload

My code below works fine so long as I only load 2 multiple files. If I load 3 or more, every file after the 2nd one does not get added to my s3 bucket (although no error is shown by plupload).
Can anyone understand why?
var uploader = new plupload.Uploader({
browse_button: 'browse', // this can be an id of a DOM element or the DOM element itself
url: 'https://s3.amazonaws.com/mybucket',
filters: {
max_file_size: '25mb',
prevent_duplicates: true,
multiple_queues: true
}
});
uploader.init();
uploader.bind('FilesAdded', function (up, files) {
plupload.each(files, function (file) {
var myFileName = file.name.toLowerCase();
myFileName = myFileName.replace(/[|&;$%#"<>()+,]/g, "");
var elem = $('#hfReplyGuid');
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "WebService.asmx/prepareUpload",
data: "{'acl':'private','bucket':'myBucket','file':'" + folderPath + elem.val() + "_" + myFileName + "'}",
success: function (data) {
params[myFileName] = { policy: data.d[0].Policy, signature: data.d[0].Signature };
var multipart_params = {
'key': folderPath + elem.val() + "_" + myFileName,
'filename': folderPath + elem.val() + "_" + myFileName,
'AWSAccessKeyId': AWSAccessKey,
'acl': 'private',
'signature': params[myFileName]["signature"],
'policy': params[myFileName]["policy"],
'success_action_status': '201'
}
up.setOption('multipart_params', multipart_params);
uploader.start();
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(xhr.responseText);
alert(thrownError);
}
});
});
});
I solved this by basing code on this post Upload multiple files to Amazon S3 using plupload
However I had to create the policies in the FileFiltered event, start the uploader in the FilesAdded event and then add each policy in the BeforeUpload event as below:
var multipart_params = policies[file.id];
up.setOption('multipart_params', multipart_params);

Jqgrid: Access Selected Row Cell value in Code behind

I want to access the selected row cell id in the code behind. I can do it either by Ajax call but it is not possible when i try to send the data from the Jqgrid Subgrid.
Below is the Subgrid code:
subGridRowExpanded: function (subgrid_id, row_id) {
debugger;
var subgrid_table_id, pager_id; subgrid_table_id = subgrid_id + "_t";
var selected_row_id = $('#tblFormData').jqGrid('getCell', row_id, 'Category_Id')
// pager_id = "p_" + subgrid_table_id;
$("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + pager_id + "' class='scroll'></div>");
$("#" + subgrid_table_id).jqGrid({
// $("#tblTest").jqGrid({
url: "/Forms.aspx/GetFormsData", //?selected_row_id=" + selected_row_id,
data: '{"CategoryDesc":"' + selected_row_id + '"}',
datatype: "json",
contentType: "application/json; charset=utf-8",
loadonce: true,
width: "300",
height: "auto",
pager:"#tblSubpager",
colNames: ['FormName','FormPath'],
colModel: [
{ name: "FormName", index: "FormName", editable: true, formatter: 'showlink' },
//{ name: "FormPath", index: "FormPath", editable: true, hidden: true },
{
name: 'FormPath',
index: 'FormPath',
hidden: true,
enctype: "multipart/form-data",
editable: true,
edittype: 'file',
editrules: {
edithidden: true,
required: true
},
formoptions: {
elmsuffix: '*'
}
}
],
gridview: true,
autoencode: true,
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj.d; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.d.length; }
}
});
below is the function which i call it from the URL in Vb.NET.
<WebMethod> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function GetFormsData(CategoryId As String) As List(Of Dictionary(Of String, String))
Using dt As DataTable = DirectCast(DataAccess.ExecuteStoredProcedure("AFI_DYNAMIC", "Ashley.dbo.usp_GetDownloadFormsDetails", DataAccess.StoredProcedureReturnType.DataTable), DataTable)
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows1 As New List(Of Dictionary(Of String, String))()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object)
Dim row1 As Dictionary(Of String, String)
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
row1 = New Dictionary(Of String, String)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName, dr(col))
'string sb = "Yahoo!";
Next
rows.Add(row)
'For i As Integer = 0 To dt.Columns.Count - 1
Dim sb As String = "" & dr("FormName").ToString() & ""
'Next
row1.Add(dt.Columns(0).Caption, sb)
rows1.Add(row1)
Next
Return rows1
End Using
End Function
Now i want to Access the CategoryId in my code behind Can anybody help me on this.
The code have clear many problems. I post below some clear problems which I could find by reading of the code:
Is CategoryId the column of the parent grid? Is $('#tblFormData') the parent grid? In the case you could use $(this) instead of $('#tblFormData').
You use pager_id as id of <div> of the pager for subgrid, but the line which assign the value for pager_id is commented and id is undefined. Instead of that you use pager:"#tblSubpager" which is wrong.
jqGrid has no contentType parameter. So you should remove it. Instead of that you use already ajaxGridOptions parameter with contentType. It's correct parameter.
You use data: '{"CategoryDesc":"' + selected_row_id + '"}', but the server code expect parameter with the name CategoryId and not CategoryDesc. By the way jqGrid has no data parameter in case of usage datatype: "json". What you mean should be postData. Correct will be to use
postData: {
CategoryId: selected_row_id
}

Dynatree init from custom json data

There is an example on the website on how to construct child nodes from custom data:
$("#tree").dynatree({
[…]
onLazyRead: function(node){
$.ajax({
url: […],
success: function(data, textStatus){
// In this sample we assume that the server returns JSON like
// { "status": "...", "result": [ {...}, {...}, ...]}
if(data.status == "ok"){
// Convert the response to a native Dynatree JavaScipt object.
var list = data.result;
res = [];
for(var i=0, l=list.length; i<l; i++){
var e = list[i];
res.push({title: "" + i + ": " + e.fcurr + "-" + e.tcurr + ":" + e.ukurs,
icon: false});
}
// PWS status OK
node.setLazyNodeStatus(DTNodeStatus_Ok);
node.addChild(res);
}else{
// Server returned an error condition: set node status accordingly
node.setLazyNodeStatus(DTNodeStatus_Error, {
tooltip: data.faultDetails,
info: data.faultString
});
}
}
});
[…]
});
But there is no mention on how to do this for the initialization of the tree. I tried the following:
initAjax: {
type: "POST",
url: "/doSomething",
data: ...
contentType: "application/json; charset=utf-8"
success: function(data, textStatus){
// In this sample we assume that the server returns JSON like
// { "status": "...", "result": [ {...}, {...}, ...]}
if(data.status == "ok"){
// Convert the response to a native Dynatree JavaScipt object.
var list = data.result;
res = [];
for(var i=0, l=list.length; i<l; i++){
var e = list[i];
res.push({title: "" + i + ": " + e.fcurr + "-" + e.tcurr + ":" + e.ukurs,
icon: false});
}
// PWS status OK
node.setLazyNodeStatus(DTNodeStatus_Ok);
node.addChild(res);
}else{
// Server returned an error condition: set node status accordingly
node.setLazyNodeStatus(DTNodeStatus_Error, {
tooltip: data.faultDetails,
info: data.faultString
});
}
}
},
But then I get an error saying success doesn't work and to use some other method, but there is no documentation on how to use the other method? Can anyone help me out here? I tried using dataFilter to filter out my json string that is being returned, but that didn't work; I tried to use onPostInit and postProcess but don't know exactly what to do since there is no documentation: Do I return the data string after its been reformated, do I return the json version of the data? do I just do data = format(data)?
Any help would be greatly appreciated.
I will be having a lot of status codes and need to do different things based on the code; such as if I have code 1 it means I need to change the class of the node to have red text; or if I return code 2 it means there was an internal error and I need to add that to the node text; etc.