views:

118

answers:

2

I have code that "pops up" another ASPX page with an image in it. The javascript used to popup the the window is below.

            string url = @"DocumentPage.aspx?imageGuid=" + imageGuid;
            string winWidth = "800";
            string winHeight = "600";

            StringBuilder scriptString = new StringBuilder();

            scriptString.Append("<script language='JavaScript'> function openDocument(){");
            scriptString.Append("var url = " + "'" + url + "';");
            scriptString.Append("var wndw = window.open(url,'','width= " + winWidth + ",height=" + winHeight + ",resizable=Yes,status=Yes,scrollbars=Yes,menubar=Yes');");
            scriptString.Append("if ((document.window != null) && (!wndw.opener)) wndw.opener = document.window;");
            scriptString.Append("} openDocument();<");
            scriptString.Append("/");
            scriptString.Append("script>");

The image renders in this DocumentPage.aspx fine. In IE 7 when I click the File -> Print, this action alone causes this DocumentPage.aspx to fire a PostBack and the Page property of IsPostBack is false, so it essentially runs through the same code it executed on page pop up.

Has anyone run across this Browser -> File -> Print causing post backs in asp.net? If so do you have a work around to stop this? (Its not doing anything to break the pages functionality, its just really annoying for wasting resources with unneeded postback calls).

A: 

Yes I am having same problem. Did you solve this?

Jig
A: 

Do you have any page routes defined in your global.asax?

I found I was getting the same thing because we had page routes defined in the global.asax pointing to this page and then I had a printing css style on the page which contained a path to an image in the same path format as the page route.

So when the print or print preview tried to load the image it then resolved to this page. I moved the image and changed the print css style (so that it didn't correspond to any routes defined in the global.asax) which worked for me.

James_2195