I try to output CSV file in pop-up window. I can output CSV in main window, but not in pop-up. I use same code. For example; I use a form to output CSV file. When this form is main window, can output CSV file. When I use this form as a pop-up, it can't output. How can I do?
It is my CSV output function:
public void OutputCSV(DataTable dtValue, string strFilename)
{
if (TextUtility.IsNullOrEmpty(strFilename))
{
throw new I01Exception(Enums.ExType.System, "9909_35");
}
DataTable dt = dtValue;
StringBuilder sb = new System.Text.StringBuilder();
string strCh = ",";
//項目名
for (int k = 0; k < dt.Columns.Count; k++)
{
sb.Append("\"" + dt.Columns[k].Caption + "\"" + strCh);
}
sb.Remove(sb.Length - 1, 1);
//データ
foreach (DataRow row i开发者_StackOverflow中文版n dt.Rows)
{
sb.AppendLine(string.Empty);
for (int i = 0; i < dt.Columns.Count; i++)
{
sb.Append("\"" + row[i].ToString() + "\"" + strCh);
}
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AppendHeader("content-disposition", string.Format("attachment; filename={0}", HttpUtility.UrlEncode(strFilename + ".csv")));
HttpContext.Current.Response.ContentType = "text/comma-separated-values";
HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("shift-jis");
HttpContext.Current.Response.Write(sb.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
HttpContext.Current.Response.End();
}
just add a href with tartget="_new" pointing to your url from the web page. If you need a popup withint he windows best option is to use a jquery pop libary they take externla url's. If you are trying to use the native javascript popup this is a dialog box ment only for text ??
Following on from Simon Thompson's answer (good answer simon).
I think your approaching this from the wrong side. A popup is not something created on the server side, instead it is something created on the client-side either in pure html or javascript.
So for example:
<a href="http://google.com" target="_blank">open google in a popup</a>
Here is some more details about popup's: http://www.quirksmode.org/js/popup.html
The quirksmode tutorial is a useful introduction, however to implement I would not use the approach and instead use a more "unobtrusive" approach (but i'd look into this later once you have a grasp of the popup fundamentals).
精彩评论