2

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

3 回答 3

0

将您的代码更改为以下

 onClientClick="return Validate();"
于 2012-10-24T06:19:18.773 回答
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();"

于 2012-10-24T06:43:15.803 回答
0

将此脚本放到您的表单中:

 function pageLoad(sender, args) {
      if (args.get_isPartialLoad() === false) {
           $find("<%= ModalPopupExtender1.ClientID %>").add_showing(function (sender, args) { args.set_cancel(Validate()); });
      }
 }
于 2012-10-24T07:03:25.650 回答