Handsontable Grid-从ASPX网页加载和保存数据 [英] Handsontable Grid - loading and saving data from aspx web page

查看:92
本文介绍了Handsontable Grid-从ASPX网页加载和保存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用aspx页面背面的c#代码将数据加载到网格或从网格保存数据,还是必须使用Web服务(或PHP)?我尝试过使用JSON.Net映射一个非常简单的结构来编码后端结构的尝试失败了

Is it possible to load and save data to/from a grid using c# code in the back from an aspx page, or does one have to use a web service (or PHP)? I have tried and failed using JSON.Net to map a very simple structure to code a backend structure

是否可以使用JQuery(我猜想是ajax GET)对后端代码文件(.aspx.cs)中的方法进行调用?我已经尝试过使用该论坛上各种帖子中的代码,但是有关后端代码(c#)的信息很少,而且所有内容似乎都涉及Web服务.任何帮助/建议将不胜感激.

Is it possible to use JQuery (an ajax GET I presume) to make a call to a method in the backend code file (.aspx.cs)? I have tried using code from various posts on this forum, but there is little information on the backend code (c#), and all seem to refer to web services. Any help/advice would be much appreciated.

以下是关联的JavaScript代码:

Here is the JavaScript code associated:

var handsontable = $container.data('handsontable');
$(document).find('button[name=load]').click(function () {
    $.ajax({
        url: "Default.aspx/getJSData",
        dataType: 'json',
        type: 'GET',
        //contentType: "application/json; charset=utf-8",
        success: function (res) {
            handsontable.loadData(res.data);
            $console.text('Data loaded');
        },
        error: function () {
            $console.text('Load error');
        }
    });

});

推荐答案

您仍然需要进行Ajax调用,但不需要进行Web服务(可以).您想要暴露给Ajax调用的函数将[WebMethod]属性设置为打开,并使用将EnablePageMethods属性设置为true的脚本管理器.

You still need to do an Ajax call but you don't need to do a web service (you can). The function you want exposed to the Ajax call put the [WebMethod] Attribute on and an use a Script Manager with the EnablePageMethods attribute set to true.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
</asp:ScriptManager>

访问方法:

[WebMethod]
public static void SomeFunction(string message, string name)
{

}

使用jQuery进行Ajax调用

Ajax call using jQuery

(function($) {
        $.ajax({
            type: "POST",
            url: "test.aspx/SomeFunction",
            data: "{message:'Hello World', name: 'Bob'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                alert('success');
            }
        });
    });

参考:使用WebMethod属性

这篇关于Handsontable Grid-从ASPX网页加载和保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆