Helper function to Print Page using JScript(including inside frame)

            ///<summary>
            /// Helper function to Print Page using JScript(including inside frame) 
            ///</summary>
            ///<param name="page"></param>
            public static void PrintPage(Page page)
            {
                //In case if page is in frameset, you need to call parent.window.print()
                String script = @"
if (parent!= self)
{ parent.window.print();
}
else
{
    window.print();
}
";
                RegisterOnceStartupScript(page,TypeForClientScript(), MethodBase.GetCurrentMethod().Name,script,true);
            }
            public static bool RegisterOnceStartupScript(Page page, Type type,   string key, string script, bool addScriptTags)
            {
                bool bRet=false;
                if(false==page.ClientScript.IsStartupScriptRegistered(type,key))
                {
                    page.ClientScript.RegisterStartupScript(type, key, script, addScriptTags);
                    bRet = true;
                }
                return bRet;
            }
 
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Sunday, June 01, 2008 2:48 PM
Print

Comments on this entry:

# re: Helper function to Print Page using JScript(including inside frame)

Left by web development company at 8/18/2009 2:33 AM
Gravatar
Hey, that was interesting,

so this is how print button works in different websites,I simply never thought about How it was implemented

Thanks for writing, most people don't bother.

# re: Helper function to Print Page using JScript(including inside frame)

Left by Generic Oxytrol at 12/20/2010 3:07 AM
Gravatar
This is by far the best looking site I’ve seen. It was completely easy to navigate and it was easy to look for the information I needed. Fantastic layout and great content!

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910