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;
            }
 

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.

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345