【问题标题】:Disable UpdateProgress for one UpdatePanel为一个 UpdatePanel 禁用 UpdateProgress
【发布时间】:2017-04-11 02:23:04
【问题描述】:

我正在对具有许多 UpdatePanel 和 UpdateProgress 控件的 ASP.NET Web 窗体应用程序进行一些更改。

我添加了一个 UpdatePanel,并且仅针对此 UpdatePanel,我想在此 UpdatePanel 更新时停止显示所有 UpdateProgress。

许多 UpdateProgress 控件没有设置 AssociatedUpdatePanelID,因此它们会在我更新我的新 UpdatePanel 时显示。

有没有办法在没有设置 AssociatedUpdatePanelID 的情况下将 UpdatePanel 排除在触发 UpdateProgress 之外?可能是一些 JavaScript?

我在这里找到了一些解决方案,但它们要求您知道 UpdateProgress 的 ID。整个应用程序中有很多 UpdateProgress,我不想逐个指定。

【问题讨论】:

    标签: asp.net webforms


    【解决方案1】:

    好的,所以没有答案,我进一步调查并提出了客户端解决方案。

    如果 UpdateProgress 控件没有关联的 UpdatePanel,并且触发部分回发的 UpdatePanel 至少有一个与之关联的 UpdateProgress,则此脚本将禁止显示它们。

    长话短说:如果 UpdatePanel 具有关联的 UpdateProgress 控件,那么只有在触发部分回发时才会显示它们。

    <script type="text/javascript">
    
        //array of original values
        var updateProgressDefaults = [];
    
        Sys.Application.add_init(appl_init);
    
        function appl_init() {
    
            var c = Sys.Application.getComponents();
            for (var i = 0; i < c.length; i++) {
                if (Object.getType(c[i]).getName() == "Sys.UI._UpdateProgress" && !c[i]._associatedUpdatePanelId) {
                    updateProgressDefaults[c[i].get_id()] = c[i]._associatedUpdatePanelId;
                };
            }
    
            var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();
            pgRegMgr.add_initializeRequest(BeginHandler);
            pgRegMgr.add_endRequest(EndHandler);
        }
    
        function BeginHandler(sender, args) {
            //There is no _updatePanelsToUpdate if a trigger is outside of an UpdatePanel
            if (!args._updatePanelsToUpdate) return;
    
            //Check if the affected UpdatePanel has an associated UpdateProgress control
            var hasUpdateProgress = false;
    
            var c = Sys.Application.getComponents();
            for (var i = 0; i < args._updatePanelsToUpdate.length; i++) {
                for (var j = 0; j < c.length; j++) {
                    if (Object.getType(c[j]).getName() == "Sys.UI._UpdateProgress" && args._updatePanelsToUpdate[i].replace(/\$/g, "_") == c[j]._associatedUpdatePanelId) {
                        hasUpdateProgress = true;
                        break;
                    }
                }
    
                if (hasUpdateProgress) break;
            }
    
            //If the UpdatePanel has an associated UpdateProgress control then set all the UpdateProgress controls without associated UpdatePanels to a non-existant UpdatePanel
            if (hasUpdateProgress) {
                for (var i = 0; i < c.length; i++) {
                    var id = c[i].get_id();
                    var type = Object.getType(c[i]).getName();
                    if (type == "Sys.UI._UpdateProgress" && !c[i]._associatedUpdatePanelId) {
                        c[i]._associatedUpdatePanelId = "NullUpdateProgress";
                    };
    
                }
            }
        }
    
        //Restores AssociatedUpdatePanelId for all UpdateProgress controls
        function EndHandler() {
            for (var key in updateProgressDefaults) {
                $get(key).control._associatedUpdatePanelId = updateProgressDefaults[key];
            }
        }
    </script>
    

    来源:Disable common UpdateProgress controls for an UpdatePanel with an associated UpdateProgress

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      • 1970-01-01
      • 2011-03-25
      • 2016-01-14
      • 1970-01-01
      相关资源
      最近更新 更多