Hi,
Hi I have Bootstrap Popup Open On Page Button Click,
On Popup I Have Download Button.
After Clicking On Download Button Excel File Download,
But Popup Remains Open.
So How Can We Close Popup After Response.Write().
 I am Posting My Code. Please any one Give me Solution For That.
 
Thanks In Advance.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5"
    EnableEventValidation="false" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandle);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandle);
        function beginRequestHandle(sender, Args) {
        }
        function endRequestHandle(sender, Args) {
        }        
    </script>
    <uc:Header ID="header" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div>
                <div>
                    <table>
                        <tr>
                            <td align="left" valign="top">
                                <asp:LinkButton ID="lnk_Show" runat="server" TabIndex="1" CssClass="btn btn-primary"
                                    Font-Bold="true" OnClick="lnk_Show_Click"><i class="glyphicon glyphicon-search"></i> Show</asp:LinkButton>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="modal fade" id="div_Popup1" data-keyboard="false" data-backdrop="static"
                    tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
                    style="display: none;">
                    <div class="modal-dialogR4">
                        <div class="modal-contentR4">
                            <div class="modal-headerR4">
                                <div>
                                    <div>
                                        <asp:Label ID="lbl_Sales_Msg" runat="server" Text="Download Data" Font-Size="14px"
                                            ForeColor="White" Font-Bold="true" /></div>
                                    <div style="float: right; text-align: right; padding-right: 3px; margin-top: -25px;">
                                        <span class="glyphicon glyphicon-remove-circle" style="color: white; cursor: pointer;
                                            font-size: 1.8em;" title="Close Popup.!" onclick="Close_div_Popup1_Popup();">
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-bodyR4">
                                <div style="display: inline-block; width: 100%;">
                                    <div style="padding-left: 5px; padding-right: 5px; padding-top: 8px;">
                                        <asp:Panel ID="Panel1" runat="server" DefaultButton="lnk_Download">
                                            <div>
                                                <div style="float: left; padding-left: 07px; padding-top: 2px;">
                                                    <asp:LinkButton ID="lnk_Download" runat="server" TabIndex="3" CssClass="btn btn-primary"
                                                        Font-Bold="true" OnClick="lnk_Download_Click"><i class="glyphicon glyphicon-edit"></i> Download</asp:LinkButton>
                                                </div>
                                            </div>
                                        </asp:Panel>
                                    </div>
                                </div>
                                <br />
                                <br />
                            </div>
                            <div class="modal-footerR4">
                                <div>
                                </div>
                                <br />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </ContentTemplate>
        <Triggers>
            <%-- <asp:PostBackTrigger ControlID="lnk_Show"/>--%>
            <asp:PostBackTrigger ControlID="lnk_Download" />
        </Triggers>
    </asp:UpdatePanel>
    <uc:Footer ID="footer" runat="server" />
    <style type="text/css">
        #div_Popup1 .modal-headerR4
        {
            font-size: 16px !important;
            color: White !important;
            background-color: #0090CB !important;
            padding: 10px 5px !important;
            text-align: center !important;
        }
        #div_Popup1 .modal-dialogR4
        {
            max-width: 400px !important;
            margin: 30px auto !important; /*padding-right: 15px !important;*/
        }
        #div_Popup1 .modal-contentR4
        {
            position: relative !important;
            background-color: #fff !important;
            -webkit-background-clip: padding-box !important;
            background-clip: padding-box !important;
            border: 1px solid #999 !important;
            border: 1px solid rgba(0,0,0,.2) !important;
            border-radius: 6px !important;
            outline: 0 !important;
            -webkit-box-shadow: 0 3px 9px rgba(0,0,0,.5) !important;
            box-shadow: 0 3px 9px rgba(0,0,0,.5) !important;
            top: 65px !important; /* left: 15px !important;*/
            margin-bottom: 25px !important;
            margin-left: 25px !important;
            margin-right: 25px !important;
        }
        #div_Popup1 .modal-bodyR4
        {
            position: relative !important;
            padding-left: 2px !important;
            padding-right: 2px !important;
            padding-bottom: 0px !important;
            padding-top: 3px !important;
        }
        #div_Popup1 .modal-footerR4
        {
            padding: 5px !important;
            text-align: left !important;
            border-top: 1px solid #e5e5e5 !important;
            background-color: #e5e5e5 !important;
            height: 50px !important;
        }
    </style>
    <script type="text/javascript">
        function Open_div_Popup1_Popup() {
            $(".modal-backdrop").remove();
            $('#div_Popup1').modal('show');
            $(".modal-backdrop fade in").remove();
        }
        function Close_div_Popup1_Popup() {
            $(".modal-backdrop").remove();
            $('#div_Popup1').modal('hide');
            $(".modal-backdrop fade in").remove();
        }
    </script>
    </form>
</body>
</html>
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
public partial class Default5 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void lnk_Show_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "Open_div_Popup1_Popup();", true);
    }
    protected void lnk_Download_Click(object sender, EventArgs e)
    {
        StringBuilder sb = Get_Data_To_Export(Get_Data());
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.Charset = "";
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=R11.xls");
        HttpContext.Current.Response.Write(sb.ToString());
        HttpContext.Current.Response.Write("<script>Close_div_Popup1_Popup();</script>");
       
        
        HttpContext.Current.Response.Flush();
        //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "Close_div_Popup1_Popup();", true);
        HttpContext.Current.Response.End();       
        HttpContext.Current.ApplicationInstance.CompleteRequest();
        
    }
    protected void lnk_Download1_Click(object sender, EventArgs e)
    {
        StringBuilder sb = Get_Data_To_Export(Get_Data());
        Response.Clear();
        Response.Buffer = true;
        Response.BufferOutput = true;
        Response.Charset = "UTF-8";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
        Response.AppendHeader("Content-disposition", "attachment; filename=R11.xls");
        Response.Write(sb.ToString());
        Response.Flush();
        //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "Close_div_Popup1_Popup();", true);
        Response.End();
        Response.Close();
        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
    public DataTable Get_Data()
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
                            new DataColumn("Name", typeof(string)),
                            new DataColumn("Country",typeof(string)) });
        dt.Rows.Add(1, "AAAA", "AAAAA");
        dt.Rows.Add(2, "BBBBB", "BBBB");
        dt.Rows.Add(3, "CCCC", "CCCCC");
        dt.Rows.Add(4, "DDDD", "DDDD");
        dt.Rows.Add(5, "EEEE", "EEEE");
        dt.Rows.Add(6, "FFFF", "FFFF");
        dt.Rows.Add(7, "GGGG", "GGGG");
        dt.Rows.Add(8, "HHHH", "HHHH");
        return dt;
    }
    public StringBuilder Get_Data_To_Export(DataTable dt)
    {
        StringBuilder sb = new StringBuilder();
        // Render out an HTML table to pass into Excel
        sb.Append("<table cellpadding='4' cellspacing='1' border='1'>");
        // Get all column names
        sb.Append("<tr>");
        foreach (DataColumn dc in dt.Columns)
        {
            sb.Append("<td align='center' valign='middle' style='background-color:#85A7CC;'>");
            sb.Append("<b>" + dc.ColumnName.Replace("_", " ").ToUpper() + "</b>");
            sb.Append("</td>");
        }
        sb.Append("</tr>");
        // Handle table rows and cells
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.Append("<tr>");
            foreach (DataColumn dc in dt.Columns)
            {
                string align_Type = "";
                if (dc.DataType == typeof(string))
                {
                    align_Type = "left";
                }
                if (dc.DataType == typeof(int) | dc.DataType == typeof(decimal) | dc.DataType == typeof(double))
                {
                    align_Type = "right";
                }
                sb.Append("<td align='" + align_Type + "' valign='middle'>");
                sb.Append(dt.Rows[i][dc].ToString().ToUpper());
                sb.Append("</td>");
            }
            sb.Append("</tr>");
        }
        // Close the table tag
        sb.Append("</table>");
        return sb;
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }
}