ASP.NET AJAX 回发中止

发布于 2024-11-27 00:54:48 字数 2219 浏览 0 评论 0原文

我有一个 ASP.NET 网页,其中包含两个回发事件,第二个事件正在中止第一个事件。第二个任务完成后不会按预期呈现。

详细信息

我有一个 ASP.NET 网页,它实际上包含两个链接按钮。它使用 Telerik ASP.NET AJAX 控件,但我不确定该行为是否特定于这些控件:

页面 - 一个极其精简的版本如下如下:

<telerik:RadToolTipManager ID="RadToolTipManager1" runat="server"
  Position="BottomLeft" RelativeTo="Element" ShowEvent="OnClick" 
  HideEvent="ManualClose" Animation="Fade" OnAjaxUpdate="OnShowItems" >  
     <TargetControls>
          <telerik:ToolTipTargetControl TargetControlID="btnShowItems" />
     </TargetControls>
</telerik:RadToolTipManager>
...
...
<asp:LinkButton ID="btnShowItems" runat="server" Visible="false">
     <span><%= ItemsPrompt %></span>
</asp:LinkButton>
...
...
<uc1:X ID="XControl" runat="server"/>

用户控件“X” - 一个极其精简的版本如下:

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
  LoadingPanelID="LoadingPanel1" RenderMode="Block">
    <asp:LinkButton runat="server" ID="CausePostbackButton" 
      Style="display: none" />
</telerik:RadAjaxPanel>

用例#1 - 成功

  1. 页面加载,并且 Control“X”内的 JavaScript 计时器激活LinkBut​​ton“CausePostbackButton”上的回发 [eval(__doPostBack(postbackButtonClientID,''));]。 (因此,这模仿了用户单击按钮)。
  2. AJAX 调用发送至服务器,n 秒后返回并导致页面以特定方式更新。
  3. 然后,用户单击 LinkBut​​ton“btnShowItems”,这会导致回发到服务器,n' 秒后返回并导致页面以特定方式更新。

用例 #2 - 失败

  1. 页面加载,控件“X”内的 JavaScript 计时器激活 LinkBut​​ton“CausePostbackButton”上的回发。 (因此,这模仿用户单击按钮)。

  2. 在服务器有时间响应之前,用户单击 LinkBut​​ton“btnShowItems”。

  3. 在FireFox/Firebug中,您可以看到第一个回发事件是“Aborted”。第二个回发事件完成(您可以看到报告的所用时间),但页面未在视觉上更新。

  4. 如果再次单击“手动”按钮,则按预期工作。

我的想法

  • 我知道 JavaScript 是单线程的,所以如果事件不能立即运行,那么它们就会排队。

  • 我知道,如果计时器触发一个已排队的事件,然后在第一个事件仍在排队时触发同一事件,那么其中一个事件(第二个?)将被丢弃。

  • 这就像第一个事件被丢弃,但第二个事件无法再找到要写入的“通道”。

但是,如果我将“手动”链接按钮更改为图像按钮,则行为不会改变。

任何想法是什么问题(最好是一个解决方案)?

非常感谢

格里夫

I have an ASP.NET web page with two postback events and the second one is aborting the first. The second one then doesn't render as expected once it completes.

In Detail

I have an ASP.NET web page that effectively contains two link buttons. It uses the Telerik ASP.NET AJAX controls, but I'm not sure if the behaviour is specfic to these controls:

The Page - an extremely cut-down version is as follows:

<telerik:RadToolTipManager ID="RadToolTipManager1" runat="server"
  Position="BottomLeft" RelativeTo="Element" ShowEvent="OnClick" 
  HideEvent="ManualClose" Animation="Fade" OnAjaxUpdate="OnShowItems" >  
     <TargetControls>
          <telerik:ToolTipTargetControl TargetControlID="btnShowItems" />
     </TargetControls>
</telerik:RadToolTipManager>
...
...
<asp:LinkButton ID="btnShowItems" runat="server" Visible="false">
     <span><%= ItemsPrompt %></span>
</asp:LinkButton>
...
...
<uc1:X ID="XControl" runat="server"/>

The UserControl "X" - an extremely cut-down version is as follows:

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
  LoadingPanelID="LoadingPanel1" RenderMode="Block">
    <asp:LinkButton runat="server" ID="CausePostbackButton" 
      Style="display: none" />
</telerik:RadAjaxPanel>

Use Case #1 - successful

  1. The page loads and a JavaScript timer within Control "X" activates a postback on the LinkButton "CausePostbackButton" [eval(__doPostBack(postbackButtonClientID,''));]. (So, this mimics a user clicking the button).
  2. The AJAX call goes to the Server and n seconds later it returns and results in the page updating in a particular way.
  3. The user then clicks the LinkButton "btnShowItems" which causes a post-back to the Server and n' seconds later it returns and results in the page updating in a particular way.

Use Case #2 - failure

  1. The page loads and a JavaScript timer within Control "X" activates a postback on the LinkButton "CausePostbackButton". (So, this mimics a user clicking the button).

  2. Before the server has time to respond, the User clicks on the LinkButton "btnShowItems".

  3. In FireFox/Firebug, you can see that the first post-back event is "Aborted". The second post-back event completes (you can see the time taken reported) but the page is not visually updated.

  4. If the "manual" button is then clicked again, then that works as expected.

My thoughts

  • I know that JavaScript is single threaded, so if events can't be run immediately then they are queued.

  • I know that if a timer fires an event that is queued and then fires the same event whilst the first event is still queued, then one of these events (the second?) will be dropped.

  • This is acting as if the first event is being trashed, but then the second event can no longer find its "channel" to write to.

However, if I change the "manual" Link Button to an Image Button then the behaviour does not change.

Any ideas what the problem is (and ideally a solution)?

Many thanks in advance

Griff

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隐诗 2024-12-04 00:54:49

按照迪克·兰帕德的建议,我们直接联系了 Telerik。他们立即想出了解决方案:

根据设计,如果您在收到第一个请求的响应之前尝试启动另一个请求,则 ASP.NET AJAX 框架会取消正在进行的 ajax 请求。例如,将 RadAjaxPanel 的 RequestQueueSize 设置为 3...

成功了!

As Dick Lampard suggested, we contacted Telerik directly. They immediately came up with the solution:

By design ASP.NET AJAX Framework cancels the ongoing ajax request if you try to initiate another one prior to receiving the response from the first one. Set the RequestQueueSize for the RadAjaxPanel to 3 for example...

That worked!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文