【问题标题】:ModalPopupExtender gets stuck in Show when same TargetControlID is activated当激活相同的 TargetControlID 时,ModalPopupExtender 卡在 Show 中
【发布时间】:2021-11-06 11:36:43
【问题描述】:

我有一个与 RadListBox 绑定的 ModalPopupExtender,因此当从列表框中选择一个项目时,我需要一个“请稍候”消息,而后面的页面将数据加载到 RadCharts 中。加载完成后,Modal 会隐藏。我遇到的问题是,如果再次选择相同的列表项,模态弹出窗口会再次显示,但永远不会消失。我已经尝试了几乎所有东西,但是在 RadListBox 中单击/选择列表项会立即显示模态,我似乎无法找到一种方法来检查项目是否相同,然后什么也不做.

这是我的面板和模态代码 (ASPX)

<asp:Panel ID="pnlProgress" runat="server" Height="50px" Width="50px" >
     <div>
        <div class="popupbody">
            <table width="50%">
                <tr>
                    <td align="center">
                    <asp:Image ID="imgProgress" runat="server" ImageUrl="~/_images/ajax-loader.gif" />
                    <br />
                    <br />
                    <asp:Label ID="lblLoading" runat="server" Text='Please wait...'
                         Font-Bold="true"></asp:Label>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</asp:Panel>

<ajaxToolKit:ModalPopupExtender ID="mpeProgress" runat="server" TargetControlID="lboxTestedMachines" PopupDragHandleControlID="pnlProgress" `enter code here`
X="1000" Y="500" PopupControlID="pnlProgress" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowResize" BehaviorID="lboxTestedMachines">
</ajaxToolKit:ModalPopupExtender>

这是我的 ASPX.CS 代码

        protected void lboxTestedMachines_SelectedIndexChanged(object sender, EventArgs e)
    {
        int iResultID = Convert.ToInt32(lboxTestedMachines.SelectedValue);

        if (tbl_charts.Style.Value != "display:normal")
            tbl_charts.Style.Value = "display:normal";

        GetMachineName(iResultID);

        RdListView_Chart.DataSource = LoadCassetteForFoodChart(iResultID);

        GetApprovalRejectionStatus(iResultID);

    }

【问题讨论】:

  • 尚未使用 Telerik 控件,但是,您可以尝试在代码隐藏中隐藏 pnlProgress - 更具体地说是 mpeProgress 吗?喜欢 - mpeProgress.Hide?
  • 嗨,Marco... 您认为何时/何地/在什么事件上实现这一点?我之所以问,是因为我确实在几乎所有内容上都设置了断点,当您单击列表框中的一项时,会显示等待模式并且没有达到一个断点。就像当你将 TargetControlID 与 ModalPopupExtender 结合时,有一层无法访问或控制的处理。
  • 首先尝试lboxTestedMachines_SelectedIndexChanged 事件,否则,请查看文档并查看您可以通过代码隐藏访问的ModalPopupExtender 事件。
  • 嗨,Marco,我在帖子中提供的 lboxTestedMachines_SelectedIndexChanged 事件,这就是启动 Show Modal 流程的事件。就像我说的,我不能在那个过程之前、中间或之后。只要完成由列表框中的选定项目启动的一系列事件,模态就会显示。问题是当再次连续选择相同的确切项目时,模态再次显示,但永远不会消失。 (例如卡住)

标签: modalpopupextender selectedindexchanged radlistbox


【解决方案1】:

RadListBox 在单击项目时有一个内部逻辑,以确定项目是否已被选中。如果是,则不会触发 OnClientSelectedIndexChanging 事件,因此在单击选定项目时不会回发。

另一方面,ModalPopupBehavior 对 TargetControlID 控件元素内的任何点击事件作出反应。以下是使用浏览器的 DevTools 获得的一些代码 sn-ps(按照Get IntelliSense for the client-side object 中的步骤搜索Sys.Extended.UI.ModalPopupBehavior.prototype.initialize

initialize: function() {
    Sys.Extended.UI.ModalPopupBehavior.callBaseMethod(this, "initialize"),
        this._isIE6 = Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7,
        this._popupDragHandleControlID && (this._dragHandleElement = $get(this._popupDragHandleControlID)),
        this._popupElement = $get(this._popupControlID),
        this._createDomElements(),
        this._showHandler = Function.createDelegate(this, this._onShow),
        $addHandler(this.get_element(), "click", this._showHandler),
        this._okControlID && (this._okHandler = Function.createDelegate(this, this._onOk),
            $addHandler($get(this._okControlID), "click", this._okHandler)),
        this._cancelControlID && (this._cancelHandler = Function.createDelegate(this, this._onCancel),
            $addHandler($get(this._cancelControlID), "click", this._cancelHandler)),
        this._scrollHandler = Function.createDelegate(this, this._onLayout),
        this._resizeHandler = Function.createDelegate(this, this._onLayout),
        this.registerPartialUpdateEvents(),
        this._resetAnimationsTarget(),
        this._onHiding.get_animation() && (this._hidingAnimationEndedHandler = Function.createDelegate(this, function () {
            this._isAnimationJustEnded = !0,
                this.hide()
        }),
            this._onHiding.get_animation().add_ended(this._hidingAnimationEndedHandler)),
        this._onShowing.get_animation() && (this._showingAnimationEndedHandler = Function.createDelegate(this, function () {
            this._isAnimationJustEnded = !0,
                this.show()
        }),
            this._onShowing.get_animation().add_ended(this._showingAnimationEndedHandler))
},
_onShow: function(e) {
    if (!this.get_element().disabled)
        return this.show(),
        e.preventDefault(),
        !1
},

解决方案 1: 订阅 ModalPopupBehavior 的 Showing 事件,并允许它仅在您从 OnClientSelectedIndexChanging 事件设置标志时显示。下面的示例将标志作为扩展属性存储在 RadListBox 客户端对象中:

<telerik:RadCodeBlock runat="server" ID="rdbScripts">
    <script type='text/javascript'> 
        function pageLoadHandler() {
            var modalPopupExtenderClientObject = $find("<%= mpeProgress.ClientID %>")
            modalPopupExtenderClientObject.add_showing(function (sender, args) {
                // "sender" argument represents the Modal popup control client-side object
                // sender.get_element() returns the DOM element of the RadListBox
                // sender.get_element().control return the client-side object of the RadListBox where we stored the expando property __allowModalPopupShow 
                if (sender.get_element().control.__allowModalPopupShow !== true) {
                    args.set_cancel(true);
                }
            })

        }

        function OnClientSelectedIndexChanging(sender, args) {
            // sender in this context is the RadListBox client-side object
            sender.__allowModalPopupShow = true;
        }

        Sys.Application.add_load(pageLoadHandler);
    </script>
</telerik:RadCodeBlock>

解决方案 2: 使用 RadAjaxLoading 面板并在 OnClientSelectedIndexChanging 中以编程方式显示它:

【讨论】:

  • Peter Milchev 是最棒的,他帮我找到了解决方案!非常感谢他的帮助。他还进行了跟进并回答了我的其他支持帖子,以便编程社区也可以找到解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-28
  • 1970-01-01
  • 1970-01-01
  • 2012-04-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多