Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Can anyone help me to hide Header, Footer and Page URL while printing a aspx page.
I am using vs2008 C# with asp.net


thank you
Posted

open your browser > File >Page setup >

Here uncheck header and footer and url ...set it to blank
 
Share this answer
 
You can't control this in javascript, it has to be done at the browser level.

What we've also done is generate a PDF so that you can make the page look the same across all browsers. iTextSharp is a free tool to do this. Just a note, it is kinda unfriendly. There is an example here. Basically, you input HTML and it converts it to a PDF.

Just try the following code.

For this we are using print class like it.

C#
public static void PrintWebControl(Control ctrl)
{
    PrintWebControl(ctrl, string.Empty);
}

public static void PrintWebControl(Control ctrl, string Script)
{
    StringWriter stringWrite = new StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
    if (ctrl is WebControl)
    {
        Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
    }
    Page pg = new Page();
    pg.EnableEventValidation = false;
    if (Script != string.Empty)
    {
        pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
    }
    HtmlForm frm = new HtmlForm();

    pg.Controls.Add(frm);
    // done changes on below 1 line for unassigned header URL //
    frm.ResolveUrl("");
    frm.Attributes.Add("runat", "server");
    frm.Controls.Add(ctrl);

    pg.DesignerInitialize();

    pg.RenderControl(htmlWrite);
    string strHTML = stringWrite.ToString();
    HttpContext.Current.Response.Clear();        
    HttpContext.Current.Response.Write(strHTML);
    HttpContext.Current.Response.Write("<script>window.print();</script>");
    HttpContext.Current.Response.End();
}


here just change a line in form property and set frm.ResolveUrl(""); so URl is not visible when page is print..i use it successfuly.......


[Edit member="Tadit"]
Pre tags added.
[/Edit]
 
Share this answer
 
v3
its browser handle. we cant do that.
in print open window in browser , uncheck header/footer.. thats it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900