views:

1620

answers:

11

I have a ASP.NET button on a page that opens a popup window this way:

String cstext1 = "window.open('ReportViewer.aspx');";

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), 
Guid.NewGuid().ToString(), cstext1, true);

The ReportViewer.aspx file gets some data, passes it to crystal reports and streams the PDF output back.

In IE7 the window opens and immediately closes afterwords.

I found a workaround by lowering IE security settings for the site but I would like to know if I can make it work without requiring the user to tweak his settings.

A: 

That's IE's integrated popup blocker doing its job, just as designed. I suggest you do not have the user lower the security settings. That's a bad idea. Just add the site to the popup blocker exception list (Internet Options -> Privacy -> Settings... on the popup Blocker lower half of the page -> add the site domain to the allowed sites.

Mihai Limbășan
A: 

it's not the popup blocker, I'm developing on the local machine (and the site it's on the secure sites list) and disabling the popup blocker doesn't solve the problem.

Perhaps it's associated with the fact that the Response.ContentType is "application/pdf".

Please use the add comment feature to reply to specific answers or edit the question to provide more details. SO is not a forum or a newwgroup. Use Answers only to provide answers to the question.
AnthonyWJones
sorry, just saw the comment now... after posting another reply. Can I fix this?
Perhaps you can copy your answer text and paste it as an edit to your question, then delete your answer.
Argalatyr
Not sure who/why this was downvoted, since the user is new to SO, can't comment, and had not known how to edit. +1 for balance.
Argalatyr
A: 

You need to re-arrange UI design such that the window.open is not called during page start up. If the window.open call is made during the execution of a button click (client-side javascript) the popup blocker won't eat it.

AnthonyWJones
A: 

It's not the popup blocker, odd thing the page actually opens and immediately closes, if it was a blocked popup it wouldn't open in the first place.

+2  A: 

Ok, I solved it.

It was IE not allowing the fact that a file with a .aspx suffix had a content type of application/pdf and a header with "Content-Disposition:attachment;".

I built and configured a Http Handler that manages a *.pdf verb. The handler does exactly what the ReportViewer.aspx did, but in a ProcessRequest method (thus implementing IHttpHandler).

In this way IE thinks the Url requested is in fact a pdf file (and it doesn't require the Content-Disposition).

If anyone needs the code I'll post it.

How do I close the question?...
I think you need to accept an answer, but I understand why you don't want to accept one of these. As one option, so that the correct answer is accepted, I'll just post your text as a quote in a new answer. If you choose not to do it this way, I can just delete the answer. Just a thought.
Argalatyr
Another user chided me for this approach, so I deleted my answer that quoted you. I don't have enough rep to close this for you, You should be able to edit your original question (just flag as "Edit:" and say what you learned.
Argalatyr
Just an FYI: You're allowed to accept your own answer.
Mark Biek
Giorgio please can you send me the solution please ??
Myra
A: 

Giorgio,

If you can post the code when you get a chance, I would greatly appreciate it. I am running into this problem as well.

Thanks!

A: 

Hi,

Could you please post the solution code? I'm having the same exact issue.

Jason

A: 

Please paste the code here - there have been people helped you with this situation, its about time you gave something back.

Many thanks

A: 

Hi everyone - since the original author will not post the answer I managed to research this all out myself. Its really quite simple just follow the points on this page: http://www.15seconds.com/Issue/020417.htm

A: 

Please post code as that article really isn't helpful

A: 

I am experiencing the same problem. I am doing a Page.RegisterClientScriptBlock and the window pops up then closes on its own. I may have to make the LinkButton a HyperLink and set the href and target="_blank" when the control is bound.

joeldow