开发者

Http Response Object in new window

I have a button click event set up to retrieve a byte array object from my DB and it is then going to show the file in a new browser window. Right now I have this much开发者_StackOverflow:

Response.ContentType = "image/jpeg";
Response.AddHeader("content-length", fileBytes.Length.ToString());
Response.BinaryWrite(fileBytes);

where fileByes is my byte array. This is working perfectly, but I need to force this to open in a new window. I have tried adding the javascript to the response with response.write but that doesn't seem to work.


Writing your response is handled server side. Displaying your response is handled client side. You would have to tell your client to open a new window given the response from the server, e.g.

<a href="getImage.aspx" target="_blank">Get Image</a>

Where getImage.aspx is the ASP.NET page responsible for serving the image/page.


You can't open a new window from server-side code. You'll need to call window.open() from JavaScript and pass in a URL to a page that returns the file.


You'd want to have your button click open the new browser window, which then makes the call to your code you have posted in your question. You're trying to do it sort of backwards.


Use a hyperlink with a URL to a blank .aspx,
pass a parameters in the URL as ?param=4&param2 ... etc.
In the load event for the page place your response code there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜