停止弹出ModalPopup Extender

时间:2012-10-24 06:08:16

标签: c# javascript .net ajax ajaxcontroltoolkit

我有一个模式弹出扩展器,它会在按钮单击时触发...现在无论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>

3 个答案:

答案 0 :(得分:0)

将您的代码更改为以下

 onClientClick="return Validate();"

答案 1 :(得分:0)

您可以从javascript打开Popup

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();”

答案 2 :(得分:0)

将此脚本放在表单上:

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