AjaxControlToolkit Modalpopup OkControlID -vs- asp:按钮OnClick事件

时间:2012-11-08 15:59:04

标签: vb.net ajaxcontroltoolkit

我有一个AjaxControlToolkit ModalPopupExtender,允许选择要压缩和下载的文件。填充模态弹出窗口的asp:Panel中的asp:按钮具有OnClick属性,该属性引用sub后面的代码。这可以正常工作,直到将OkControlID属性添加到asp:ModalPopupExtender以便于关闭弹出窗口...然后忽略OnClick ...有人知道如何在弹出窗口中拥有相同的asp:Button,调用一个codebehind sub并关闭弹出窗口?

asp:Panel ID="DownLoadForm" runat="server" CssClass="download-form">
    <div class="download-header">Files Available For Download</div>
    <ul>
        <li><asp:CheckBox ID="CheckBox1" runat="server" checked="true" enabled="false"/> File 1</li>
        <li><asp:CheckBox ID="CheckBox2" runat="server" /> File 2</li>
        <li><asp:CheckBox ID="CheckBox3" runat="server" /> File 3</li>
        <li><asp:CheckBox ID="CheckBox4" runat="server" /> File 4</li>
        <li>&nbsp;</li>
        <li>
            <asp:Button ID="btnZipAndDownload" runat="server" Text="Zip And Download" OnClick="Download"/>
            <asp:Button ID="btnCancelDownload" runat="server" Text="Cancel" />
        </li>
    </ul>

</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupDownload" runat="server"
    PopupControlID="DownLoadForm"
    TargetControlID="btnDownloadFiles"
    CancelControlID="btnCancelDownload"
    OkControlID="btnZipAndDownload" >
</asp:ModalPopupExtender>

后面的代码中的sub是“Download”

Protected Sub Download(ByVal sender As Object, ByVal e As System.EventArgs)
    Try
        Dim FileName As String = "~/Mock_Files.zip"
        Response.AddHeader("Content-disposition", "attachment; filename=Mock_Borrower_Files.zip")
        Response.ContentType = "application/zip"
        Response.WriteFile(FileName, False)

    Catch ex As Exception
        Foo
        Foo too
    End Try

    Response.End()

End Sub

1 个答案:

答案 0 :(得分:1)

您可以使用OnClientClick属性并使用__doPostBack函数调用强制回发:

<asp:Button ID="btnZipAndDownload" runat="server" Text="Zip And Download" OnClick="Download"
    OnClientClick="__doPostBack(this.name, '')" />