views:

1960

answers:

3

How can I hide the header like 'Page 1 of 1' and footer (url) when printing a webcontol in ASP.NET?

I currently doing by opening a new page on Print button click ande in it

protected void Page_Load(object sender, EventArgs e)
{
    if( null != Session["Control"] )
    {
        Control ctrl = ( Control )Session["Control"];
        PrintManager.PrintWebControl( ctrl );
        Session["Control"] = null;
    }
}

This will print the header and footer. How to avoid it?

+1  A: 

That setting is configured by the user in their browser. Their is no way to disable it from code. You'r best bet is to include instructions on how to configure/disable the settings.

See an example here: http://www.xheo.com/products/sps/default.aspx?print=true

Paul Alexander
Really, why the downvote?
Paul Alexander
+1  A: 

You should use CSS styles and specify they apply to a media type of print. See this article for help; http://www.cantoni.org/articles/printstyle

Basically create a seperate stylesheet for print styles only. If you want to hide something on the page use { display:none } as one of that elements style attributes. Then link your stylesheet in the HEAD element;

<link href="print.css" media="print" type="text/css" rel="stylesheet" />
Dave Anderson
This definately helps when printing but still doesn't eliminate the settings that the user has chosen in their browser...at least not for IE.
Paul Alexander
Right, I slightly misunderstood the question, I see they mean the actual browsers print header and footer. I guess Firefox may have this ability somewhere but IE is too closed.
Dave Anderson
A: 

If you're using Firefox, and you can have the client install an add-on, here is your answer:

https://addons.mozilla.org/en-US/firefox/addon/8966

Otherwise, if you are using Internet Explorer:

google "MeadCo ScriptX"

(FF option is free, IE option is free for basic functionality only)

Joe Richards