C# 如何使用javascript在asp.net中调用函数?

C# 如何使用javascript在asp.net中调用函数?,c#,asp.net,gridview,tablednd,C#,Asp.net,Gridview,Tablednd,我正在使用jquery插件tablednd $(document).ready(function () { $('#mygridview').tableDnD(); }) onDrop: function (table, row) { __doPostBack('<%= this.UniqueID %>', 'Select'); } 使gridview中的行可拖动。 当我拖动一行时,我想调用asp.net中的函数来保

我正在使用jquery插件tablednd

$(document).ready(function () {
    $('#mygridview').tableDnD();
})
onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
使gridview中的行可拖动。 当我拖动一行时,我想调用asp.net中的函数来保存行的位置。但我在gridview上找不到一个只在单击一行时才做出反应的适当事件

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
表DND中有一个onDrop方法

$(document).ready(function () {
    $('#mygridview').tableDnD({
      onDrop: function(table, row) {
   });
})
onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
但是我如何从那里调用asp.net方法呢?我读过一些关于ajax的文章,但我不明白

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
我也读过关于使用PageMethods的文章,但它没有调用我的函数

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
问题是如何编写对数据库中的表执行更新的内容

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
更新:

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
我使用IPostBackEventHandler方法解决了这个问题

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
我必须使用IPostBackEventHandler扩展我的用户控件和页面 然后在用户控件和页面上添加了public void RaisePostBackEventstring eventArgument函数。最后:

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
如果有人对onDrop有问题,解决方法是您必须为每一行提供ID,如下所示:

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
    var i = 0;
    $("#<%= gridviewID.ClientID %>").find('tr').each(function () {
        $(this).attr('id', i++);
    });
<asp:ScriptManager runat="server"
       ID="ScriptManager1" 
       EnablePageMethods="true"
       EnablePartialRendering="true"
/>
[WebMethod]
public static string DoServerStuff(string parameter)
{
    return "Parameter passed: " + parameter;
}
function doClientStuff() {
    var result = PageMethods.DoServerStuff('test parameter');
    alert(result);
}
function doClientStuff() {
    var result = __doPostBack('<%= this.UniqueID %>', 'Select');
}
在表D的开始上方

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }

谢谢

通常有两种方法,一种是使用AJAX,另一种是使用回发

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
AJAX方式:

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
将ScriptManager添加到页面,如下所示:

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
    var i = 0;
    $("#<%= gridviewID.ClientID %>").find('tr').each(function () {
        $(this).attr('id', i++);
    });
<asp:ScriptManager runat="server"
       ID="ScriptManager1" 
       EnablePageMethods="true"
       EnablePartialRendering="true"
/>
[WebMethod]
public static string DoServerStuff(string parameter)
{
    return "Parameter passed: " + parameter;
}
function doClientStuff() {
    var result = PageMethods.DoServerStuff('test parameter');
    alert(result);
}
function doClientStuff() {
    var result = __doPostBack('<%= this.UniqueID %>', 'Select');
}
通过PageMethods类从客户端调用它,如下所示:

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
    var i = 0;
    $("#<%= gridviewID.ClientID %>").find('tr').each(function () {
        $(this).attr('id', i++);
    });
<asp:ScriptManager runat="server"
       ID="ScriptManager1" 
       EnablePageMethods="true"
       EnablePartialRendering="true"
/>
[WebMethod]
public static string DoServerStuff(string parameter)
{
    return "Parameter passed: " + parameter;
}
function doClientStuff() {
    var result = PageMethods.DoServerStuff('test parameter');
    alert(result);
}
function doClientStuff() {
    var result = __doPostBack('<%= this.UniqueID %>', 'Select');
}
对于使用jQuery执行相同的操作,请签出

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
回发方式:

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
使包含要调用的方法的页面实现IPostBackEventHandler接口。 在客户端调用_doPostback方法,如下所示:

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
    var i = 0;
    $("#<%= gridviewID.ClientID %>").find('tr').each(function () {
        $(this).attr('id', i++);
    });
<asp:ScriptManager runat="server"
       ID="ScriptManager1" 
       EnablePageMethods="true"
       EnablePartialRendering="true"
/>
[WebMethod]
public static string DoServerStuff(string parameter)
{
    return "Parameter passed: " + parameter;
}
function doClientStuff() {
    var result = PageMethods.DoServerStuff('test parameter');
    alert(result);
}
function doClientStuff() {
    var result = __doPostBack('<%= this.UniqueID %>', 'Select');
}
在页面的IPostBackEventHandler.RaisePostBackEvent方法内实现服务器端逻辑

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }
更多关于从客户端发起回发的信息

onDrop: function (table, row) {
                __doPostBack('<%= this.UniqueID %>', 'Select');
            }

可能与我得到的错误重复:将IPostBackEventHandler{}添加到我的页面类时,我所有的类上都应该有类、委托、枚举、接口或结构。你知道为什么吗?问题在于方法。您不应该使用gridview和ajax更新。如果您想使用TabledND,最好使用ajax调用填充表。因为gridview的数据绑定是一个服务器端事件,而tableDnD中的更新是一个客户端事件。当使用AJAX方法时:我得到一个错误:没有定义PageMethods。使用回发方式时:在将IPostBackEventHandler{}添加到我的Page类时,我在所有类上获得了预期的类、委托、枚举、接口或结构。请确保:1。您已经为ScriptManager 2指定了一个Id。其EnablePageMethods设置为true和3。您的服务器方法在页面上而不是用户控件OK,那么它将不起作用,服务器方法在用户控件中。是的,它不会,但您仍然可以使用IPostBackEventHandler选项;我尝试了IPostBackEventHandler选项,当我删除我的行时,站点会进行回发,但它从不执行我的RaisePostBackEvent函数。我已使用IPostBackEventHandler扩展了我的页面。