繁体   English   中英

停止ModalPopup Extender弹出

[英]Stop ModalPopup Extender to popup

我有一个模式弹出窗口扩展程序,它会在单击按钮时触发...现在,无论onclientclick函数返回值true / false,它始终会弹出。 我需要停止在返回false时触发模态,并在返回到true时触发模态。如何执行此操作?

请在下面找到代码:

<div style="text-align:center;" runat="server" id="pnlButton">          
    <asp:Button  CssClass="button" ID="btnBack" runat="server" Text="Back" 
        Width="120px" onclick="btnBack_Click" UseSubmitBehavior="false" />
    &nbsp;
    <asp:Button  CssClass="button" ID="btnCancel" runat="server" 
            Text="Cancel Request" Width="130px" onclick="btnCancel_Click" onClientClick="Validate();" />
</div>
<div style="text-align:center;">
<asp:Button  CssClass="button" ID="btnDone" Visible="false" runat="server" 
        Text="Done" Width="110px" onclick="btnDone_Click"   />
</div>

<ajaxToolkit:ConfirmButtonExtender ID="cbe" runat="server"
TargetControlID="btnCancel"
DisplayModalPopupID="ModalPopupExtender1"
ConfirmText="Are you sure you want to click this?" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnCancel"
PopupControlID="PNL" OkControlID="ButtonOk" CancelControlID="ButtonCancel" BackgroundCssClass="modalBackground" />
<asp:Panel ID="PNL" runat="server" Style="display: none; width: 400px; background-color: White;
    border-width: 2px; border-color: Black; border-style: solid; padding: 20px;">
    <h2>Are you sure you want to cancel this request?</h2>
    <br />
    <br />
    <div style="text-align: right;">
        <asp:Button ID="ButtonOk" runat="server" Text="Yes" CssClass="button" />&nbsp;&nbsp;
        <asp:Button ID="ButtonCancel" runat="server" Text="No" CssClass="button" />
    </div>
</asp:Panel>

将您的代码更改为以下内容

 onClientClick="return Validate();"

您可以从javascript打开弹出窗口

function ValidateAndOpen(){
if(Validate()){
var modalDialog = $find("ModalPopupExtender1"); 
// get reference to modal popup using the AJAX api $find() function    
  if (modalDialog != null) {
    modalDialog.show();
  }    
 }
return false;
}

您必须在ModalPopupExtender上设置ClientIDMode =“ Static”并设置OnClientClick =“ return ValidateAndOpen();”

将此脚本放到表单上:

 function pageLoad(sender, args) {
      if (args.get_isPartialLoad() === false) {
           $find("<%= ModalPopupExtender1.ClientID %>").add_showing(function (sender, args) { args.set_cancel(Validate()); });
      }
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM