【问题标题】:One update panel updated and other one is also updated?一个更新面板更新了,另一个也更新了?
【发布时间】:2009-07-24 12:48:22
【问题描述】:

我有场景,页面上有两个更新面板(都有更新模式='条件')。如果我更新一个更新面板,另一个会自动更新。这是第一个问题。

我正在使用 UpdatePanelAnimationExtender。如果一个更新面板被更新,则没有 updatepanelAnimationExtender 另一个也更新,并且有 updatepanelAnimationExtender, OnUpdatingUpdatePanel();事件被触发。 正如 updatepanelAnimationExtender 的文档所说: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/UpdatePanelAnimation/UpdatePanelAnimation.aspx

OnUpdating - 当任何UpdatePanel 开始更新时播放通用动画

OnUpdated - 在UpdatePanel 完成更新后播放的通用动画(但仅当UpdatePanel 已更改)

问题: OnUpdating 已被触发,它在后端工作但未完成,因为 onUpdated 仅在 UpdatePanel 更改时触发

【问题讨论】:

  • 更新面板如何相互关联?也就是说,一个嵌套在另一个里面吗?每个的 ChildrenAsTriggers 设置是什么?
  • 它们不相互关联也不嵌套.....
  • 只要你自己做测试页就可以测试了....就像...
  • 在页面上添加 2 个更新面板,为两者设置 updatemode='conditional' 并为更新面板添加加载事件并为加载事件设置断点并添加 1 个按钮,然后为按钮单击添加 Asyn 触发器1 个更新面板....当您点击按钮时,您会注意到,它应该只加载触发的更新面板,而第 2 个保持不变,但第 2 个更新面板的加载事件也被触发...

标签: asp.net ajax updatepanel animationextender


【解决方案1】:

“在页面上添加 2 个更新面板,为两者设置 updatemode='conditional' 并为更新面板添加加载事件并为加载事件设置断点并添加 1 个按钮,然后为按钮单击 1 个更新面板添加 Asyn 触发器。 ...您会注意到,当您点击按钮时,它应该只加载触发的更新面板,而第二个保持不变,但第二个更新面板的加载事件也会触发”

仅当按钮位于第二个更新面板内时才会发生这种情况?如果没有,那么我认为它不会更新第二个更新面板。您能否确认该按钮是在第二个更新面板内部还是外部?

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。同一页面上的两个更新面板未嵌套且 UpdateMode="Conditional"。只要意识到当页面上的一个更新面板触发部分回发时,所有更新面板都会触发更新事件。如果您将 UpdatePanelAnimationExtender 连接到 UpdatePanel A,并且为不相关的 UpdatePanel B 触发了部分回发,则两者都会触发更新事件,并且 UpdatePanel A 的动画将只运行 OnUpdating 部分而不是 OnUpdated 部分(所以基本上动画会跑到一半)。

    这就是我解决此问题的方法: 确定触发了哪个更新面板。这可以通过获取脚本管理器的表单变量的值来找到。有问题的更新面板将在字符串中提及。使用此信息根据您的需要执行操作。

    // Variable to hold ScriptManager.  Just slap this in the class for the page.
    private ScriptManager scriptManager;
    
    // Get the ScriptManager.  Put this in Page_Init handler.
    // If you have the ScriptManager on the same page, just refer to it directly.
    // If you have it on the master page, you can get a reference to it like so.
    // The second line shows one way you can get a reference to the ScriptManager from
    // a user control.
    // FYI, the same code applies to a ToolkitScriptManager.
    scriptManager = ScriptManager.GetCurrent(this);
    // scriptManager = ScriptManager.GetCurrent(HttpContext.Current.Handler as Page);
    
    // This function checks whether an UpdatePanel is being updated
    private Boolean IsUpdatePanelUpdating(String sUPID)
    {
        String sUpdateValue = Request.Form[Request.Form.AllKeys.Where(s => s.EndsWith(scriptManager.ClientID)).FirstOrDefault()] ?? String.Empty;
        return sUpdateValue.Contains(sUPID);
    }
    
    // This is code you can put somewhere (say within OnLoad handler) to make an
    // UpdatePanel A get updated even if an unrelated UpdatePanel B is currently being
    // updated.
    if (!IsUpdatePanelUpdating(upA.ClientID))
        upA.Update(); 
    

    我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-14
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多