We have a very slow ASP.NET page with a repeater. It is slow because most of the processing is done in the ItemDataBound event of the repeater. All this processing just gets 2 totals to be shown in each row.
我们有一个非常慢的ASP.NET页面和一个转发器。它很慢,因为大多数处理都是在转发器的ItemDataBound事件中完成的。所有这些处理只需要在每一行中显示2个总计。
To increase the throughput, it could be a good idea to load the repeater without ItemDataBound event and without the 2 totals. Instead on loading the page in browser, AJAX calls can be made from each row and totals can be shown asyncronously.
为了提高吞吐量,最好在没有ItemDataBound事件且没有2个总计的情况下加载转发器。而不是在浏览器中加载页面,可以从每一行进行AJAX调用,并且可以同步显示总数。
Can you point to any code example where this kind of solution is achieved.
你能指出实现这种解决方案的任何代码示例吗?
Thanks!
1 个解决方案
#1
Indeed the jQuery.ajax() call is a good option here. You can use it to call a WebMethod defined in your codebehind
实际上,jQuery.ajax()调用在这里是个不错的选择。您可以使用它来调用代码隐藏中定义的WebMethod
As for the server side calculation, you have a couple options:
至于服务器端计算,您有几个选项:
-
Embed the values necessary to preform the calculation into HiddenFields within each row and pass them to your webmethod via parameters in the ajax() call.
将计算所需的值嵌入到每行中的HiddenFields中,并通过ajax()调用中的参数将它们传递给webmethod。
-
Pass a unique ID for the row using a similar method as above (HiddenField) and do your calculation based on that ID.
使用与上面类似的方法(HiddenField)为行传递唯一ID,并根据该ID进行计算。
As for the code, it could look something like this:
至于代码,它可能看起来像这样:
$('span.show-total').hover(
function(){
// Show panel here
$.ajax({
type: "POST",
url: "PageName.aspx/MethodName",
data: '{"uniqueId":"' + $(this).find('input[id$=YourHiddenFieldID]').val() + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do something interesting here.
alert(msg.d);
}
});
},
function(){
// Hide panel here
}
);
#1
Indeed the jQuery.ajax() call is a good option here. You can use it to call a WebMethod defined in your codebehind
实际上,jQuery.ajax()调用在这里是个不错的选择。您可以使用它来调用代码隐藏中定义的WebMethod
As for the server side calculation, you have a couple options:
至于服务器端计算,您有几个选项:
-
Embed the values necessary to preform the calculation into HiddenFields within each row and pass them to your webmethod via parameters in the ajax() call.
将计算所需的值嵌入到每行中的HiddenFields中,并通过ajax()调用中的参数将它们传递给webmethod。
-
Pass a unique ID for the row using a similar method as above (HiddenField) and do your calculation based on that ID.
使用与上面类似的方法(HiddenField)为行传递唯一ID,并根据该ID进行计算。
As for the code, it could look something like this:
至于代码,它可能看起来像这样:
$('span.show-total').hover(
function(){
// Show panel here
$.ajax({
type: "POST",
url: "PageName.aspx/MethodName",
data: '{"uniqueId":"' + $(this).find('input[id$=YourHiddenFieldID]').val() + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do something interesting here.
alert(msg.d);
}
});
},
function(){
// Hide panel here
}
);