在JavaScript中使用if-sause查询刷新的更新范围



我已经在更新progress-control中的图像与modalpopupextender结合使用。要在加载站点时打开扩展器,请使用以下JavaScript:

<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(showPopup);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(hidePopup);
    function showPopup(sender, args) {
        var ModalControl = '<%= ModalPopupExtender1.ClientID %>';
        $find(ModalControl).show();
    }
    function hidePopup(sender, args) {
        var ModalControl = '<%= ModalPopupExtender1.ClientID %>';
        $find(ModalControl).hide();
    }
</script> 

这很好,但是扩展器现在打开每个请求。仅当特定的UpdatePanel被迫刷新(UpdatePanelMain)时,它才能打开。我该如何在JavaScript中这样做:if(postbackelement == updatePanelMain)或其他?

获取UpdatePanels ID并找到您赢了一个可以运行的一个,您可以将args.get_postBackElement().id函数使用为:

function showPopup(sender, args) {
     // get the Post ID and compare it with the one you let run
     if(args.get_postBackElement().id == "<%=UpdatePanelMain.ClientID%>")
     {
       var ModalControl = '<%= ModalPopupExtender1.ClientID %>';
       $find(ModalControl).show();
     }
}

类似的问题:如何获取ID更新面板,该面板在JavaScript中初始请求

,因此我要寻找的解决方法。感谢Aristos的提示。

var UpdPanelsIds = args.get_updatePanelsToUpdate();
if (UpdPanelsIds[0] != "") {
    if (UpdPanelsIds[0] != "ctl00$cpMain$UpdatePanelMenue" || args.get_postBackElement().id == '<%= refreshButton.ClientID %>') {
        var ModalControl = '<%= ModalPopupExtender1.ClientID %>';
        $find(ModalControl).show();
    }
}

任何结论如何使此代码有点"更好"?

最新更新