究竟什么时候调用 Page.RegisterAsyncTask ? [英] When exactly do Page.RegisterAsyncTask's get called?

查看:19
本文介绍了究竟什么时候调用 Page.RegisterAsyncTask ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了与在 ASP.NET 页面上使用 RegisterAsyncTask、ViewState 和复选框注册的异步代码相关的令人困惑的行为,我需要确切地知道这些异步任务何时相对于 ViewState 被保存的时间运行.

I am running into confusing behavior related to async code registered on an ASP.NET page with RegisterAsyncTask, ViewState, and checkboxes, and I need to know exactly when these async-tasks run relative to when ViewState is saved.

我在 ASP:PlaceHolder 控件中有几个复选框.我正在阅读记录并填充复选框,然后我使占位符可见.

I have a few checkboxes inside an ASP:PlaceHolder control. I am reading a record and populating the checkboxes, then I make the PlaceHolder visible.

如果所有这些都是同步的——也许在 Page_Load 内——一切都很好.

If all this is synchronous - maybe within Page_Load - all is well.

如果这被注册为异步任务,则会发生以下情况:

If this is registered as an async task the following happens:

  1. 复选框被填充.
  2. 占位符可见.
  3. 在回发时,不能取消选中复选框.也就是说,如果它们最初被选中,即使用户取消选中它们,它们也会保留其选中状态.似乎复选框恢复到它们的初始值.如果在客户端上选中了一个复选框,那就成功了!取消选中不会.

这似乎不是文本框的问题.我还没有尝试过其他小部件.

This doesn't seem to be a problem with textboxes. I haven't tried other widgets.

我可以通过在注册异步任务之前将 PlaceHolder 设置为可见来纠正"这个问题.我认为这类似于我关于网格可见性的另一个问题:

I can 'correct' this problem by setting the PlaceHolder to be visible BEFORE I register the async task. I think this is similar to my other question about Grid visiblity:

asp:DataGrid 可见性与异步?

当我尝试从异步方法中提取所有可见性规则时,结果变得非常困难并导致代码混乱.

It's turning out to be very difficult and resulting in confusing code as I try to pull all the visiblity-rules out of async methods.

我从 ASP.NET 页面生命周期中看到,它在 OnPreRender 之前的某个时间被保存.我还认为 RegisterAsyncTask 的代码大约在同一时间运行.这是按什么顺序发生的?如果在我的代码运行之前保存了 ViewState,我就沉没了!

I see from the ASP.NET page lifecycle that gets saved sometime before OnPreRender. I also think RegisterAsyncTask'd code gets run about the same time. What order does this happen in? If ViewState is saved before my code runs I'm sunk!

我发现了更多细节,但仍然令人困惑:此页面的中途:http://www.asp.net/web-forms/overview/performance-and-caching/using-asynchronous-methods-in-aspnet-45 它说

I found some more detail but it is still confusing: Halfway down this page: http://www.asp.net/web-forms/overview/performance-and-caching/using-asynchronous-methods-in-aspnet-45 it says

与 RegisterAsyncTask 关联的方法将在 PreRender 后立即运行."

"Methods hooked up with RegisterAsyncTask will run immediately after PreRender."

此页面:https://msdn.microsoft.com/en-us/library/ms178472(v=vs.85).aspx 详细介绍了 PreRender 和 SaveStateComplete 事件,但没有提到 RegisterAsyncTask.我需要试验一下,看看它们之间是否有问题.

This page: https://msdn.microsoft.com/en-us/library/ms178472(v=vs.85).aspx details the PreRender and SaveStateComplete events but doesn't mention RegisterAsyncTask. I need to experiment to see if its shoe-horned between them.

推荐答案

ExecuteRegisteredAsyncTasks 可让您更好地控制何时开始任务.

The ExecuteRegisteredAsyncTasks gives you some more control in when the tasks are being started.

ExecuteRegisteredAsyncTasks 方法在点在页面处理时任何注册的异步任务,如果它们存在,则为非异步页面调用.这个自动对 ExecuteRegisteredAsyncTasks 的调用发生在PreRenderComplete 事件.

The ExecuteRegisteredAsyncTasks method is automatically called at the point in the page processing when any registered asynchronous tasks, if they exist, are invoked for a non-asynchronous page. This automatic call to ExecuteRegisteredAsyncTasks occurs just before the PreRenderComplete event.

来自 PreRenderComplete 文档:

From PreRenderComplete documentation:

这是保存页面视图状态之前引发的最后一个事件.

This is the last event raised before the page's view state is saved.

这篇关于究竟什么时候调用 Page.RegisterAsyncTask ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆