简体   繁体   English

用于按钮btnCsv的AsyncPostBackTrigger多次调用,一次单击可多次下载同一Csv文件

[英]AsyncPostBackTrigger for button btnCsv calling multiple times and downloading same Csv file multiple time in one click

I have two buttons on my page which are triggering AsyncPostBack multiple time and downloading same Csv file multiple time in one click. 我的页面上有两个按钮,它们可多次触发AsyncPostBack并一次单击即可多次下载相同的Csv文件。

      <asp:UpdatePanel ID="UpdatePanel8" runat="server" UpdateMode="Conditional" Visible="true">
                        <ContentTemplate>
                            <asp:ImageButton ID="btnpdf" ClientIDMode="Static" ImageUrl="EPHTimages/pdf.png"
                                runat="server" OnClientClick="ShowDropDownPDF();" Style="width: 0px; height: 0px;"
                                OnClick="btnpdf_Click" data-toggle="tooltip" title="Export PDF" />
                            <asp:ImageButton ID="btnCsv" ImageUrl="EPHTimages/csv.png" runat="server" OnClientClick="ShowDropDown();"
                                Style="width: 0px; height: 0px;" ClientIDMode="Static" OnClick="btnCsv_Click"
                                data-toggle="tooltip" title="Export CSV" />
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnpdf" EventName="click" />
                            <asp:AsyncPostBackTrigger ControlID="btnCsv" EventName="click" />
                        </Triggers>
                    </asp:UpdatePanel>

Java Script code for CSV Creation CSV创建的Java脚本代码

     $(document).ready(function () {
        var app = Sys.Application;
        app.add_init(ApplicationInit);
        function ApplicationInit(sender) {
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_beginRequest(BeginRequestHandler);
            if (!prm.get_isInAsyncPostBack()) {
                prm.add_endRequest(EndRequest);
            }
        }
        function BeginRequestHandler(sender, args) {
            debugger
            PostbackControl = args.get_postBackElement();
        }
        function EndRequest(sender, args) {
            var activetabname = $("div [class='tab-pane active']").attr('name');
            if (PostbackControl.id == 'btnpdf' & activetabname == "HideAndShowSummarize") {
                var iframe = document.createElement('iframe');
                iframe.src = 'ExportPDFForViz.aspx';
                iframe.style.display = 'none';
                document.body.appendChild(iframe);
                if ($("#hidDropValue").val() != "HideAndShowSummarize") {
                    var delay = 9000; //1 seconds
                    setTimeout(function () {
                        $("#overlay").hide();
                        $(".web_dialog_overlay").hide();
                        $("#divProgress").hide(); $(".web_approve").hide();
                    }, delay);
                }
                else {
                    $("#overlay").hide();
                    $(".web_dialog_overlay").hide();
                    $("#divProgress").hide(); $(".web_approve").hide();
                }

            }
            else if (PostbackControl.id == 'btnCsv') {
                var iframe = document.createElement('iframe');
                iframe.src = 'MapExportCsv.aspx';
                iframe.style.display = 'none';
                document.body.appendChild(iframe);
                return;

            }

        }
    });

I am initiating click event of update panel button (btnCsv) control using other html button control . 我正在使用其他html按钮控件启动更新面板按钮(btnCsv)控件的click事件。

<a href="" id="btnCsvlink" onclick="" style="color: Black" aria-label="Export">Export</a>

Java Script to call btnCsv $("#btnCsvlink").click(function () { event.preventDefault(); $("#btnCsv").click(); return false; }); 调用btnCsv的Java脚本$("#btnCsvlink").click(function () { event.preventDefault(); $("#btnCsv").click(); return false; });

Change your javascript to 将您的JavaScript更改为

$("#btnCsvlink").click(function (e) {
     e.preventDefault();
     $("#btnCsv").click();
     return false;
 });

without the event parameter, I don't think you are actually preventing default behavior. 没有event参数,我认为您实际上并没有阻止默认行为。

Also, add 另外,添加

ChildrenAsTriggers="False" 

to your update panel, just in case. 以防万一。

$("#btnwindpdf") was on page load event . $(“#btnwindpdf”)在页面加载事件中。 Should be on document ready. 应该准备好文件。

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

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