ASP.Net:如何使用DOM / Javascript向转发器添加行?

时间:2022-08-24 20:08:10

I know that the asp.net repeater doesnt have a Client side object model, and we are stuck with improving the performance of many pages which have repeater/gridview with the functionality of adding rows to them by server-side code.

我知道asp.net转发器没有客户端对象模型,我们仍然坚持改进许多具有转发器/ gridview的页面的性能,并具有通过服务器端代码向它们添加行的功能。

We have used updatepanels to ajaxify the functionality adding the rows to the repeater/gridview, but the time it takes for the server trip and rendering back on the browser is not acceptable.

我们使用updatepanel来将行添加到repeater / gridview的功能,但是服务器跳转和在浏览器上渲染所花费的时间是不可接受的。

Is there some way in which this can be done on the clientside to improve the performance of adding rows to the repeater/gridview. We are using Asp.net 2.0

是否有某种方法可以在客户端上完成此操作,以提高向转发器/ gridview添加行的性能。我们正在使用Asp.net 2.0

2 个解决方案

#1


UpdatePanels still execute a full page postback, then simply update whatever content is inside the panel. That's where your slowdown is coming from.

UpdatePanel仍然执行整页回发,然后只更新面板内的任何内容。这就是你的减速来自哪里。

As for using AJAX to speed things up, you'll want to use direct AJAX calls to request only the data that you need. You can do this with ASP.NET AJAX.

至于使用AJAX来加快速度,你需要使用直接的AJAX调用来只请求你需要的数据。您可以使用ASP.NET AJAX执行此操作。

In the page_load event handler, register your AJAX. (VB.NET)

在page_load事件处理程序中,注册您的AJAX。 (VB.NET)

Ajax.Utility.RegisterTypeForAJAX(GetType(ThisPageClass))

Then, create a function that will be accessible by AJAX, like so:

然后,创建一个可由AJAX访问的函数,如下所示:

<Ajax.AjaxMethod()> _
Public Function GetNewRows() As String
    ''//do stuff
    Return jsonObj
End Function

Then, on the client side, you can call it like so:

然后,在客户端,您可以这样调用它:

ThisPageClass.GetNewRows(someCallbackFunction);

function someCallbackFunction(result) {
    var json = ParseJSON(result.value);
    for(var i=0; i<json.length; i++) {
        // do whatever
    }
}

You just have to plug in the holes!

你只需插上洞!

#2


I have found out that the Repeater control doesn't have a DOM which can be used to do client side operations like adding of rows and stuff, the only easy way out(due to some constraints) i had was to use the GridView control instead and then use its DOM and that's what i finally did.

我发现Repeater控件没有一个DOM,可以用来做客户端操作,如添加行和东西,唯一简单的方法(由于一些约束)我有使用GridView控件而不是然后使用它的DOM,这就是我最终做的。

#1


UpdatePanels still execute a full page postback, then simply update whatever content is inside the panel. That's where your slowdown is coming from.

UpdatePanel仍然执行整页回发,然后只更新面板内的任何内容。这就是你的减速来自哪里。

As for using AJAX to speed things up, you'll want to use direct AJAX calls to request only the data that you need. You can do this with ASP.NET AJAX.

至于使用AJAX来加快速度,你需要使用直接的AJAX调用来只请求你需要的数据。您可以使用ASP.NET AJAX执行此操作。

In the page_load event handler, register your AJAX. (VB.NET)

在page_load事件处理程序中,注册您的AJAX。 (VB.NET)

Ajax.Utility.RegisterTypeForAJAX(GetType(ThisPageClass))

Then, create a function that will be accessible by AJAX, like so:

然后,创建一个可由AJAX访问的函数,如下所示:

<Ajax.AjaxMethod()> _
Public Function GetNewRows() As String
    ''//do stuff
    Return jsonObj
End Function

Then, on the client side, you can call it like so:

然后,在客户端,您可以这样调用它:

ThisPageClass.GetNewRows(someCallbackFunction);

function someCallbackFunction(result) {
    var json = ParseJSON(result.value);
    for(var i=0; i<json.length; i++) {
        // do whatever
    }
}

You just have to plug in the holes!

你只需插上洞!

#2


I have found out that the Repeater control doesn't have a DOM which can be used to do client side operations like adding of rows and stuff, the only easy way out(due to some constraints) i had was to use the GridView control instead and then use its DOM and that's what i finally did.

我发现Repeater控件没有一个DOM,可以用来做客户端操作,如添加行和东西,唯一简单的方法(由于一些约束)我有使用GridView控件而不是然后使用它的DOM,这就是我最终做的。