开发者

When I serve an ASP.NET page, can I render the various controls on the page in parallel?

开发者 https://www.devze.com 2023-01-11 04:18 出处:网络
When I serve an ASP.NET page, can I render the various controls on the page in parallel? I have a few Telerik controls (RadGrids) on the page and when I step through the page being loaded, it seems a

When I serve an ASP.NET page, can I render the various controls on the page in parallel?

I have a few Telerik controls (RadGrids) on the page and when I step through the page being loaded, it seems as though the controls are databound and rendered serially. Maybe this behavior is because I am hooked in with the debugger开发者_运维问答.

Is there anyway to load the page and have select controls build on separate threads? Is that even conceptually possible or must it be done sequentially?


You have a couple of options. You could use the ASP.NET asynchronous page model. The idea would be that you load the data for each control asynchronously and then bind that data to each control as it is retrieved.

It would look something like this:

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsAsync) {
        dataSource.GetDataCompleted += 
          new GetDataCompletedEventHandler(GetDataCompleted);
        dataSource.GetDataAsync();
    }
    else {
        _yourCtl.DataSource = dataSource.GetData();
        _yourCtl.DataBind();
    }
}

void GetDataCompleted(object sender, GetDataCompletedEventArgs e) {
    _yourCtl.DataSource = e.Result;
    _yourCtl.DataBind();
}

You would do the same for each control on the page. The end result is that the time to render the page will equal the time to render the slowest-rendering control.

An alternative method would be to use AJAX to load the controls. I'm not familiar with the Telerik RadGrid control, but I would assume that it supports AJAX. Here's a link to a Telerik demo page that shows how to perform programatic client-side binding of a Telerik grid: http://demos.telerik.com/aspnet-ajax/grid/examples/client/databinding/defaultcs.aspx.


Take a look at this article I hope it gives you the right direction:

http://www.codeproject.com/Articles/38501/Multi-Threading-in-ASP-NET.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消