NET在单击行命令中创建两个函数

NET在单击行命令中创建两个函数

本文介绍了如何使用VB.NET在单击行命令中创建两个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要下载文件并在下载后显示弹出窗口。但在我的下面的代码中它只下载文件。



我尝试过:



I need to download file and also show popup after download. But in my code below it only downloading the file.

What I have tried:

If e.CommandName = "MailData" Then
    Response.Clear()
    Response.AddHeader("content-disposition", "attachment; filename=AttendanceReport.xls")
    Response.Charset = ""
    Response.ContentType = "application/vnd.ms-excel"
    Dim sw As New StringWriter()
    Dim htw As New HtmlTextWriter(sw)
    AttendanceGrid.RenderControl(htw)
    Response.Output.Write(sw.ToString())

    MailPopUp.Show()
End If

推荐答案

<script>


       function invokeCacheCheck() {
            deleteCookie();
           var timeInterval = 500; // milliseconds (checks the cookie for every half second )

           var loop = setInterval(function () {
               if (IsCookieValid()) {
                   document.getElementById('<%= btnHidden.ClientID %>').click();
                  clearInterval(loop)
               }

           }, timeInterval);
       }

       // cookies
       function deleteCookie() {
           var cook = getCookie('ExcelDownloadFlag');
           if (cook != "") {
               document.cookie = "ExcelDownloadFlag=; Path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC";
           }
       }

       function IsCookieValid() {
           var cook = getCookie('ExcelDownloadFlag');
           return cook != '';
       }

       function getCookie(cname) {
           var name = cname + "=";
           var ca = document.cookie.split(';');
           for (var i = 0; i < ca.length; i++) {
               var c = ca[i];
               while (c.charAt(0) == ' ') {
                   c = c.substring(1);
               }
               if (c.indexOf(name) == 0) {
                   return c.substring(name.length, c.length);
               }
           }
           return "";
       }


   </script>





Aspx





Aspx

<asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
        <asp:Button ID="btnDownload" OnClientClick="invokeCacheCheck()" runat="server" Text="Download" OnClick="btnDownload_Click" />
        <asp:Button ID="btnHidden" Style="display: none" runat="server" Text="hidden button" OnClick="btnHidden_Click" />





代码背后





Code Behind

protected void btnHidden_Click(object sender, EventArgs e)
       {
           MailPopUp.Show()
       }


       protected void btnDownload_Click(object sender, EventArgs e)
       {
           Response.Clear();
           Response.Buffer = true;
           Response.ClearContent();
           Response.ClearHeaders();
           Response.Charset = "";
           string FileName = "excel.xls";
           StringWriter strwritter = new StringWriter();
           HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
           Response.ContentType = "application/vnd.ms-excel";
           Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
           GridView1.RenderControl(htmltextwrtter);
           HttpCookie cookie = new HttpCookie("ExcelDownloadFlag");
           cookie.Value = "Flag";
           cookie.Expires = DateTime.Now.AddDays(1);
           Response.AppendCookie(cookie);
           Response.Output.Write(strwritter.ToString());
           Response.Flush();
           Response.End();
       }


这篇关于如何使用VB.NET在单击行命令中创建两个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 15:09