Handsontable Grid - 从aspx网页加载和保存数据

时间:2013-03-28 12:20:13

标签: c# .net handsontable

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

是否可以使用JQuery(我认为是ajax GET)来调用后端代码文件(.aspx.cs)中的方法?我曾尝试使用此论坛上各个帖子的代码,但后端代码(c#)的信息很少,而且似乎都是指Web服务。任何帮助/建议将不胜感激。

以下是相关的JavaScript代码:

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');
        }
    });

});

1 个答案:

答案 0 :(得分:0)

您仍然需要进行Ajax调用,但您不需要执行Web服务(您可以)。您希望向Ajax调用公开的函数将[WebMethod]属性置于打开状态,并使用将EnablePageMethods属性设置为true的脚本管理器。

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

访问方法:

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

}

使用jQuery调用Ajax

(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');
            }
        });
    });

参考:Using the WebMethod Attribute

相关问题