我在 UpdateProgress-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();
}
}
类似问题: How to get Id update panel that initial a request in javascript
关于javascript - 在 JavaScript 中使用 if 子句查询刷新后的 UpdatePanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13191224/