谁能在打印aspx页面时帮助我隐藏页眉,页脚和页面URL. [英] Can anyone help me to hide Header, Footer and Page URL while printing a aspx page.

查看:157
本文介绍了谁能在打印aspx页面时帮助我隐藏页眉,页脚和页面URL.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在打印aspx页面时,谁能帮助我隐藏页眉,页脚和页面URL.
我在asp.net中使用vs2008 C#


谢谢

解决方案

打开浏览器>文件>页面设置>

在这里取消选中页眉和页脚以及url ...将其设置为空白


您无法在javascript中控制它,它必须在浏览器级别完成.

我们还要做的是生成PDF,以便您可以使页面在所有浏览器中看起来都一样. iTextSharp是执行此操作的免费工具.请注意,这有点不友好.这里有一个例子.基本上,您输入HTML并将其转换为PDF.

只需尝试以下代码.

为此,我们使用类似的打印类.

 公共 静态  void  PrintWebControl(Control ctrl)
{
    PrintWebControl(ctrl,字符串 .Empty);
}

公共 静态  void  PrintWebControl(控件ctrl, 字符串脚本)
{
    StringWriter stringWrite =  StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite =  System.Web.UI.HtmlTextWriter(stringWrite);
    如果(ctrl  is  WebControl)
    {
        w =  new  Unit( 100 ,UnitType.Percentage); ((WebControl)ctrl).Width = w;
    }
    页面pg =  Page();
    pg.EnableEventValidation =  false ;
    如果(脚本!= 字符串 .Empty)
    {
        pg.ClientScript.RegisterStartupScript(pg.GetType()," ,脚本);
    }
    HtmlForm frm =  HtmlForm();

    pg.Controls.Add(frm);
    // 对于未分配的标题URL,在1行以下进行了更改//
    frm.ResolveUrl(" );
    frm.Attributes.Add(" " 服务器");
    frm.Controls.Add(ctrl);

    pg.DesignerInitialize();

    pg.RenderControl(htmlWrite);
    字符串 strHTML = stringWrite.ToString();
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.Write(strHTML);
    HttpContext.Current.Response.Write(" );
    HttpContext.Current.Response.End();
} 



这里只需在form属性中更改一行并设置frm.ResolveUrl(");因此当打印页面时URl不可见..i成功使用它....



添加了预标签.
[/Edit]


其浏览器句柄.我们不能那样做.
在浏览器的打印打开窗口中,取消选中页眉/页脚.

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

解决方案

open your browser > File >Page setup >

Here uncheck header and footer and url ...set it to blank


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.

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]


its browser handle. we cant do that.
in print open window in browser , uncheck header/footer.. thats it


这篇关于谁能在打印aspx页面时帮助我隐藏页眉,页脚和页面URL.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆