Response.Write后回发问题 [英] Problem with postback after Response.Write

查看:114
本文介绍了Response.Write后回发问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络应用程序通过

Response.Write和Response.BinaryWrite将一些二进制数据写入客户端站点的文件。这个动作完成了

以响应按钮点击,C#代码隐藏如下:


private void SubmitButton_Click(object sender,System.EventArgs e)

{

//设置将打印文件写入客户端的响应

Response.Clear();

Response.AppendHeader(" Content-Disposition",

" filename = WebPrint.prn");

Response.ContentType =" application / octet- stream" ;;


int len = CalcLength()

Response.AppendHeader(" Content-Length",len.ToString());


Response.Write(s); //写一些字符串数据

Response.BinaryWrite(buf); //写二进制数据

Response.End();

}

这很好用。但我的问题是,在浏览器打开

文件下载框并且用户保存文件后,该页面没有回复

。下载文件后,我需要将控制权转移到另一个页面,我无法做到这一点。


我试过更换Response.End与Response.Redirect没有

效果。在Response.End之后添加Server.Transfer,或者甚至到位

它没有效果 - 我可以跟踪代码并调用函数,

但是页面是永远不会回来,所以动作不会发生。


帮助???


谢谢,Russ

My web app writes some binary data to a file at the client site via
Response.Write and Response.BinaryWrite. This action is accomplished
in response to a button click, with C# code behind as follows:

private void SubmitButton_Click (object sender, System.EventArgs e)
{
// Set up the response to write the print file to the client
Response.Clear ();
Response.AppendHeader ("Content-Disposition",
"filename=WebPrint.prn");
Response.ContentType = "application/octet-stream";

int len = CalcLength ()
Response.AppendHeader ("Content-Length", len.ToString ());

Response.Write (s); // Write some string data
Response.BinaryWrite (buf); // Write binary data
Response.End ();
}
This works fine. But my problem is that after the browser puts up the
File Download box and the user saves the file, the page does not get
posted back. After the file is downloaded I need to transfer control
to another page, and I can find no way to do it.

I''ve tried replacing Response.End with Response.Redirect with no
effect. Adding Server.Transfer after Response.End, or even in place
of it has no effect - I can trace the code and the function is called,
but the page is never posted back so the action does not happen.

Help???

Thanks, Russ

推荐答案

我没看到如何继续,因为你只能将文件内容

传送给浏览器。


我会在另一个窗口打开下载页面...(一个href目标)


Patrice


-


" Russ" < RU **** @ eticomm.net> écritdansle message de

news:df ******************************** @ 4ax.com ...
I don''t see how to proceed as you can only transmit the content of the file
to the browser.

I would open the download page in another window... (a href target)

Patrice

--

"Russ" <ru****@eticomm.net> a écrit dans le message de
news:df********************************@4ax.com...
我的网络应用程序通过Response.Write和Response.BinaryWrite将一些二进制数据写入客户端站点的文件。响应按钮点击完成此操作,C#代码隐藏如下:

private void SubmitButton_Click(object sender,System.EventArgs e)
{
//设置响应以将打印文件写入客户端
Response.Clear();
Response.AppendHeader(" Content-Disposition",
" filename = WebPrint。 prn");
Response.ContentType =" application / octet-stream";

int len = CalcLength()
Response.AppendHeader(" Content-Length", len.ToString());

Response.Write(s); //写一些字符串数据
Response.BinaryWrite(buf); //写二进制数据
Response.End();
}

这很好用。但我的问题是,在浏览器打开
文件下载框并且用户保存文件后,该页面不会被回复。下载文件后,我需要将控制转移到另一个页面,我无法做到这一点。

我已经尝试用Response.Redirect替换Response.End没有
效果。在Response.End之后添加Server.Transfer,或甚至在它的位置
它没有效果 - 我可以跟踪代码并调用函数,
但页面永远不会回发,因此操作不会发生了。

帮助???

谢谢,Russ
My web app writes some binary data to a file at the client site via
Response.Write and Response.BinaryWrite. This action is accomplished
in response to a button click, with C# code behind as follows:

private void SubmitButton_Click (object sender, System.EventArgs e)
{
// Set up the response to write the print file to the client
Response.Clear ();
Response.AppendHeader ("Content-Disposition",
"filename=WebPrint.prn");
Response.ContentType = "application/octet-stream";

int len = CalcLength ()
Response.AppendHeader ("Content-Length", len.ToString ());

Response.Write (s); // Write some string data
Response.BinaryWrite (buf); // Write binary data
Response.End ();
}
This works fine. But my problem is that after the browser puts up the
File Download box and the user saves the file, the page does not get
posted back. After the file is downloaded I need to transfer control
to another page, and I can find no way to do it.

I''ve tried replacing Response.End with Response.Redirect with no
effect. Adding Server.Transfer after Response.End, or even in place
of it has no effect - I can trace the code and the function is called,
but the page is never posted back so the action does not happen.

Help???

Thanks, Russ



Patrice,谢谢你的回答但我不明白首先,为什么我能只将文件的内容传送到浏览器?通常

当我点击asmx页面上的按钮时,我可以更改页面并

将其传回,以便在回发时显示已更改的页面。

我在这里添加的是文件下载。好像在下载

文件之后我应该能够触发一些动作???我已经花了很多时间探索帮助文件并使用谷歌搜索但是

一直无法找到解释此行为的任何内容。你能给我一个合适的参考资料吗?


其次,我不明白为什么或如何使用href目标会有所帮助。

如果我在另一个页面上进行下载,我不会有同样的问题 - 即下载完成时,浏览器只会

坐在那个新窗口,我没办法让它回到原来的窗口。


另外,我想在新的

窗口启动之前或之后执行一些脚本。我可以使用会话变量完成此操作,但

仅在我可以导致加载新的aspx页面时才有效。


感谢您提供任何其他帮助。


Russ


2004年10月6日星期三20:41:52 +0200,Patrice < no **** @ nowhere.com>

写道:
Patrice, thanks for the answer but I don''t understand. First, why can
I "only transmit the content of the file to the browser"? Normally
when I click on a button in an asmx page, I can change the page and
transmit it back so that on postback the changed page is displayed.
All I am adding here is the file download. It seems like after the
file is downloaded I should be able to trigger some action??? I''ve
spent a lot of time exploring help files and searching with google but
have been unable to find anything to explain this behavior. Can you
point me to a suitable reference?

Second, I don''t understand why or how using an href target will help.
If I do the download in a different page, won''t I have the same
problem - namely that when the download is done, the browser will just
sit there in that new window and I have no way to make it go back to
the original window.

Also, I would like to execute some script before or after the new
window is launched. I can accomplish this with session variables, but
that will only work if I can cause the new aspx page to be loaded.

Thanks for any additional help.

Russ

On Wed, 6 Oct 2004 20:41:52 +0200, "Patrice" <no****@nowhere.com>
wrote:
我不知道如何继续,因为你只能传输内容

我会在另一个窗口中打开下载页面...(一个href目标)

Patrice
I don''t see how to proceed as you can only transmit the content of the file
to the browser.

I would open the download page in another window... (a href target)

Patrice






看看这是否适合你。


Response.AppendHeader(" Refresh"," 1020; URL = anotherpage.aspx")


要回答您的问题,您已发出Response.End()来表示

文件传输结束。在此之后的任何行动都不可能执行回发或

。请记住,HTTP是无状态的

协议。


" Russ"写道:
See if this works for you.

Response.AppendHeader("Refresh", "1020;URL=anotherpage.aspx")

To answer your question, you have issued the Response.End() to signal the
end of transmission of the file. It is not possible to perform a postback or
for that matter any action after that. Remember that HTTP is a stateless
protocol.

"Russ" wrote:
我的网络应用程序通过Response.Write和Response.BinaryWrite将一些二进制数据写入客户端站点的文件。响应按钮点击完成此操作,C#代码隐藏如下:

private void SubmitButton_Click(object sender,System.EventArgs e)
{
//设置响应以将打印文件写入客户端
Response.Clear();
Response.AppendHeader(" Content-Disposition",
" filename = WebPrint。 prn");
Response.ContentType =" application / octet-stream";

int len = CalcLength()
Response.AppendHeader(" Content-Length", len.ToString());

Response.Write(s); //写一些字符串数据
Response.BinaryWrite(buf); //写二进制数据
Response.End();
}

这很好用。但我的问题是,在浏览器打开
文件下载框并且用户保存文件后,该页面不会被回复。下载文件后,我需要将控制转移到另一个页面,我无法做到这一点。

我已经尝试用Response.Redirect替换Response.End没有
效果。在Response.End之后添加Server.Transfer,或甚至在它的位置
它没有效果 - 我可以跟踪代码并调用函数,
但页面永远不会回发,因此操作不会发生。

帮助???

谢谢,Russ
My web app writes some binary data to a file at the client site via
Response.Write and Response.BinaryWrite. This action is accomplished
in response to a button click, with C# code behind as follows:

private void SubmitButton_Click (object sender, System.EventArgs e)
{
// Set up the response to write the print file to the client
Response.Clear ();
Response.AppendHeader ("Content-Disposition",
"filename=WebPrint.prn");
Response.ContentType = "application/octet-stream";

int len = CalcLength ()
Response.AppendHeader ("Content-Length", len.ToString ());

Response.Write (s); // Write some string data
Response.BinaryWrite (buf); // Write binary data
Response.End ();
}
This works fine. But my problem is that after the browser puts up the
File Download box and the user saves the file, the page does not get
posted back. After the file is downloaded I need to transfer control
to another page, and I can find no way to do it.

I''ve tried replacing Response.End with Response.Redirect with no
effect. Adding Server.Transfer after Response.End, or even in place
of it has no effect - I can trace the code and the function is called,
but the page is never posted back so the action does not happen.

Help???

Thanks, Russ



这篇关于Response.Write后回发问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆