Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to clear page before response.write()

Posted on 2011-10-21
16
Medium Priority
?
884 Views
Last Modified: 2012-05-12
If dt.CreateApprovalLetter(prt, stroutput) Then
            Response.Write(stroutput)
        End If

Open in new window


In the code from my webform above, stroutput is an approval letter suitable for printing...well ALMOST suitable for printing...response.write by itself does not clear the page from which it was launched and stroutput is rendered above everything on the launching page, pushing it down but not out....
I have tried response.clear, redirecting to a blank page first, etc...so far nothing I have tried get rid of the text on the launching page gives me the result I want.

Could not find an answer that worked for me with Google, so here I am again!

Thanks in advance!!


0
Comment
Question by:codefinger
  • 10
  • 4
  • 2
16 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 37006777
You can set the response headers and content type to be a text file and perform a response.binarywrite to allow the user to download it as a text file.
0
 
LVL 17

Assisted Solution

by:jrm213jrm213
jrm213jrm213 earned 1000 total points
ID: 37006897
Hi,

so at the start of your page do

response.Buffer=true

Open in new window


then in your code

If dt.CreateApprovalLetter(prt, stroutput) Then
            Response.Clear
            Response.Write(stroutput)
            Response.Flush
            Response.End
        End If

Open in new window



at end of your page do another flush so that if you are not creating the letter your page still displays.

Response.Flush

Open in new window



This should only report to the screen what is in stroutput.
0
 

Author Comment

by:codefinger
ID: 37006927
strickdd:

I do not want the user to have to choose a location, download a file, browse to the location they chose, load the text file they downloaded into the browser, and then print it....

Is that how it would have to work in the solution you propose?

The user should just have to choose File/Print from the browser menu after the page is rendered.

(I previously tried creating a temporary htm file, but I had all sorts of problems with "Access to the path  is denied" errors before I remembered there was no need to save a temporary file on the server..)


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 28

Assisted Solution

by:strickdd
strickdd earned 1000 total points
ID: 37006973
Yes, that is what my solution would do. To handle what you are saying, I have a few options, but the best is to probably use the Media CSS for No Print - http://haacked.com/archive/2006/03/13/CSSBasedPrintingTip.aspx. This CSS class will have to be applied to EVERY element that you don't want printed though which could be a bit tedious.

The other option would be to save this text to a session variable, perform a javascript window.open that will open a page the performs the Response.Write on the session variable and includes a javascript window.print() in the onload.
0
 

Author Comment

by:codefinger
ID: 37007010
jrm213jrm213:

Your solution sounds promising, but what do you mean about:

so at the start of your page do

 response.Buffer=true


Is that supposed to be on the page load event of the launching page or the stroutput page?

Same question about end...
page unload event?
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 37007053
ok so setting outputbuffer basically writes the page to memory instead of to the screen. So you can control what gets output.

In this case at the start of your page you would set output buffering to true (which turns it on) then anything that writes to the screen writes to the buffer instead. When you reach the code that determines you want stroutput to be displayed, you clear the buffer which makes it a blank slate, you response.write your stroutput  so it is the only thing now in the buffer. Then you flush the buffer, which takes whatever is in the buffer and puts it on the screen. Then end your script because that is all you wanted on the page.

If in your page your function determines that you don't need to print this letter, and you want the page to still display without it, you need to do a response.Flush at the end of the page so that the bufffer gets put on the screen, in this case it would not contain your letter, but would contain everything else. If you don't flush the buffer at the end you will get a blank white screen.
0
 

Author Comment

by:codefinger
ID: 37007721
jrm213jrm213 and strickdd:

j's solution works, but stickdd gave me an idea that would be very cool.  I made strout to be a webform instead of a standard html file then I added a button.   Ideally, using stickdd's suggestions I should have been able to add a single button that displays, but does not print.  I put code behind the button to take the user back to the list of applicants from which they began.  If it works, it will be an ideal work flow. Launch single work page from the grid, print letter for the user, click on a button and boom, back to the grid again.

Didn't quite work though, because when the strout page loads it leaves the button behind or does not render it.  Happens that way even if I don't try to implement strickdd's tips.

Does it matter whether or not the webform actually includes form tags?  I mostly did a copy and paste of html from the original html letter into the webform.

Or perhaps I am doing something else wrong?

It will be very cool if I (uh, we) can get this to work  

(BTW FYI: I am trying to avoid javascript for now if I can, cause I stink at it and this project is on a deadline that is not giving me any time to learn.)
0
 

Author Comment

by:codefinger
ID: 37009145
Did I say something wrong?  We were having a nice exiting discussion then you guys both got real quiet!

0
 

Author Comment

by:codefinger
ID: 37011139
Ok, could not avoid the javascript, but thanks to you guys, may have it working just right.

First, using  jrm213jrm213's answers fixed the problem with the calling page printing along with the letter.

But strickdd's tip about how not to print controls on a page gave me an idea.  I added a button to the stroutput and used his tips to set it not to print.  The button invokes javascript to close the letter html and open (return to) the web application's start page.

Only remaining problem is, when I do a Print Preview from the browser, the print button is visible, so I don't know if the CSS noprint option is working.  Once I have access to a printer and can prove that the navigational controls on the page do not print with the letter, I will accept both answers and split the points.

0
 

Author Comment

by:codefinger
ID: 37011151
BTW, went back to standard HTML page for the letter.
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 37011576
If you give the controls a class called noprint and add this to your css


@media print {
      .noprint { display: none; }
}


it should stop it from printing
0
 

Author Comment

by:codefinger
ID: 37011771
Almost exactly what I had done according to strickdd's link here:

http://haacked.com/archive/2006/03/13/CSSBasedPrintingTip.aspx.

Modified it to what you (jrm213jrm213) said to do, but I can still see the button in the print preview.

0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 37011905
well I have seen some browsers not like @media print

but what you can do is create a separate style sheet with that class in it
when you link the stylesheet put media="print" in it like

<link href="/css/print.css" media="print" rel="stylesheet" type="text/css"/>

0
 

Author Comment

by:codefinger
ID: 37012107
jrm213jrm213:

So you have not bothered to click on that link, huh?  (grin)

So now we are back to strickdd's suggestion with the same problem...button still appears in print preview.   LOL.
0
 

Accepted Solution

by:
codefinger earned 0 total points
ID: 37028166
Good suggestions...then I realized if I was adding a button and javascript anyways, why not....
function ButtonReturn_onclick() {


        ButtonReturn.style.visibility = "hidden";
        TextURL2Grid.style.visibility = "hidden";
        TextGridHeight.style.visibility = "hidden";
        TextGridWidth.style.visibility = "hidden";
        
        window.print()

        var newwin;
        var vurl;
        var nextwin;
        var nextwidth;
        var nextheight;

        nextwidth = TextGridWidth.value;
        nextheight = TextGridHeight.value;

        nextwidth = screen.availWidth - 10;
        nextheight = screen.availHeight - 122


        vurl = TextURL2Grid.value;

        window.close();

//        open(vurl,nextwin,width=nextwidth,height=nextheight,scrollbars=1,resizable=1);
        f_open_window_max(vurl,nextwin)

    }

    function f_open_window_max(aURL, aWinName) {
        var wOpen;
        var sOptions;

        sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes,location=no';
        sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
        sOptions = sOptions + ',height=' + (screen.availHeight - 135).toString();
        sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

        wOpen = window.open('', aWinName, sOptions);
        wOpen.location = aURL;
        wOpen.focus();
        wOpen.moveTo(0, 0);
        wOpen.resizeTo(screen.availWidth, screen.availHeight);
        return wOpen;
    }

Open in new window


Much more reliable than the stylesheet options.
0
 

Author Closing Comment

by:codefinger
ID: 37052378
Sorry, should have cleaned my code up a little before adding it to the knowledge base...show me heading off in two different directions...hopefully you who are reading this can figure out where I actually ended up!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question