Click here to Skip to main content
15,909,604 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have two function:-

C#
protected void BtnDBExport_Click(object sender, EventArgs e)
   {
       ExportQrCodeDetails();
       ExportAllCustomerDetails();
}


public void ExportQrCodeDetails()
{

SqlConnClass connClass = new SqlConnClass();
DataTable dt = connClass.Details();
GridView gv = new GridView();
gv.AutoGenerateColumns = false;

BoundField QRID = new BoundField();
QRID.HeaderText = "QRID";
QRID.DataField = "QRID";
gv.Columns.Add(QRID);

BoundField IMAGE = new BoundField();
IMAGE.HeaderText = "QRIMAGE";
IMAGE.DataField = "QRIMAGE";
gv.Columns.Add(IMAGE);

BoundField TILEIMAGE = new BoundField();
TILEIMAGE.HeaderText = "TILEIMAGE";
TILEIMAGE.DataField = "TILEIMAGE";
gv.Columns.Add(TILEIMAGE);

BoundField TILENAME = new BoundField();
TILENAME.HeaderText = "TILENAME";
TILENAME.DataField = "TILENAME";
gv.Columns.Add(TILENAME);

BoundField TILEDESC1 = new BoundField();
TILEDESC1.HeaderText = "TILEDESC1";
TILEDESC1.DataField = "TILEDESC1";
gv.Columns.Add(TILEDESC1);

gv.DataSource = dt;
gv.DataBind();

//StringWriter sw = new StringWriter();
//HtmlTextWriter htw = new HtmlTextWriter(sw);
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.AllowPaging = false;
//Change the Header Row back to white color
gv.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < gv.HeaderRow.Cells.Count; i++)
{
gv.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
int j = 1;
//Set alternate row color
foreach (GridViewRow gvrow in gv.Rows)
{
gvrow.BackColor = System.Drawing.Color.White;
if (j <= gv.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
gv.RenderControl(htw);
Response.Write(htw);
ExportQRCodeGenerateImageTableData(sw.ToString());
}

C#
public void ExportQRCodeGenerateImageTableData(string data)
    {
        string attach = "attachment;filename=QRGenerateImage.xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attach);
        Response.ContentType = "application/ms-excel";
        Response.Write(data);
        //Response.Flush();
        Response.End();
    }


public void ExportAllCustomerDetails()
{
SqlConnClass connClass = new SqlConnClass();
//Response.ClearContent();
//Response.Buffer = true;
//Response.AddHeader("content-disposition", "attachment; filename=QRCode.xlsx");
//Response.ContentType = "application/ms-excel";
DataTable dt = connClass.GetAllCustDetails();
GridView gvCustomer = new GridView();
gvCustomer.AutoGenerateColumns = false;

BoundField CUSTID = new BoundField();
CUSTID.HeaderText = "CUSTID";
CUSTID.DataField = "CUSTID";
gvCustomer.Columns.Add(CUSTID);

BoundField CUSTNAME=new BoundField();
CUSTNAME.HeaderText="CUSTNAME";
CUSTNAME.DataField="CUSTNAME";
gvCustomer.Columns.Add(CUSTNAME);

gvCustomer.DataSource = dt;
gvCustomer.DataBind();

//StringWriter sw = new StringWriter();
//HtmlTextWriter htw = new HtmlTextWriter(sw);
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvCustomer.AllowPaging = false;
//Change the Header Row back to white color
gvCustomer.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < gvCustomer.HeaderRow.Cells.Count; i++)
{
gvCustomer.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
int j = 1;
//Set alternate row color
foreach (GridViewRow gvrow in gvCustomer.Rows)
{
gvrow.BackColor = System.Drawing.Color.White;
if (j <= gvCustomer.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
gvCustomer.RenderControl(htw);
Response.Write(htw);
ExportAllCustomerTableData(sw.ToString());
}

C#
public void ExportAllCustomerTableData(string data)
    {
        string attach = "attachment;filename=CustomerDetails.xls";
        Response.ClearHeaders();
        Response.AddHeader("content-disposition", attach);
        Response.ContentType = "application/ms-excel";
        Response.Write(data);
        Response.End();
    }


I want to call another function after one function.
but Only first function is running but another function did not run.
Second function is not calling after first's function Responce.End().

Basically second function is not calling after Response.End().
Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted
Updated 11-Oct-15 23:34pm
v2
Comments
Krunal Rohit 12-Oct-15 5:37am    
Please post the relevant code & format it properly.

-KR
Agarwal1984 12-Oct-15 5:40am    
Its a relevant code step by step.
My problem only in Responce.End().
My second function its not calling after First ExportQRCodeGenerateImageTableData's Response.End()

You can not have any function call after calling Response.End() as the End() method causes the Web server to stop processing the script and return the current result. The remaining contents of the file are not processed.

So, as an alternative solution you can create two buttons
One to export the QR code details only
and the other to export all the customer details.
 
Share this answer
 
Response.End is a finaliser: it flushes the HTML document to the client and aborts the current thread. So no further code is executed once you call the method.
https://msdn.microsoft.com/en-us/library/system.web.httpresponse.end(v=vs.110).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900