如何在c#asp.net中的Response.End()之后进行第二次函数调用? [英] How will be second function call after Response.End() in c# asp.net?
问题描述
你好,
我有两个功能: -
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。添加(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;
//将标题行改回白色
gv.HeaderRow.Style.Add(background-color,#FFFFFF );
//将stlye应用于gridview标题单元格
for(int i = 0;我< gv.HeaderRow.Cells.Count; i ++)
{
gv.HeaderRow.Cells [i] .Style.Add(background-color,#507CD1);
}
int j = 1;
//设置备用行颜色
foreach(gv.Rows中的GridViewRow gvrow)
{
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());
}
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;
//更改标题返回白色
gvCustomer.HeaderRow.Style.Add(background-color,#FFFFFF);
//将stlye应用于gridview标题单元格
for(int i = 0;我< gvCustomer.HeaderRow.Cells.Count; i ++)
{
gvCustomer.HeaderRow.Cells [i] .Style.Add(background-color,#507CD1);
}
int j = 1;
//设置备用行颜色
foreach(gvCustomer.Rows中的GridViewRow gvrow)
{
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);
ExportAllCustomerTableDa ta(sw.ToString());
}
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();
}
我想在一个函数后调用另一个函数。
但只有第一个函数正在运行,但另一个功能没有运行。
第二个函数在第一个函数后没有调用Responce.End()。
基本上是第二个函数在Response.End()之后没有打电话。
请帮帮我。
先谢谢。
Ankit Agarwal
软件工程师
调用<$ c $后无法进行任何函数调用c> Response.End()作为End()
方法导致Web服务器停止处理脚本并返回当前结果。文件的剩余内容不会被处理。
因此,作为替代解决方案,您可以创建两个按钮
一个用于导出QR代码详细信息只有
和另一个导出所有客户详细信息。
Response.End是终结者:它将HTML文档刷新到客户端并中止当前线程。因此,一旦调用该方法,就不会再执行任何代码。
https://msdn.microsoft.com/en-us/library/system.web.httpresponse.end(v = vs.110).aspx [ ^
Hello,
I have two function:-
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());
}
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());
}
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
You can not have any function call after callingResponse.End()
as theEnd()
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.
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[^]
这篇关于如何在c#asp.net中的Response.End()之后进行第二次函数调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!