"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Monday, March 28, 2011

Easy way to Print a web page

Hi *.*,
Now a day's almost all website giving us the option to print web-pages and its very simple to achieve this functionality.window.print() Is used for this.
 

Through Client Side


  <asp:Button ID="btn_Print" runat="server" Text="Print" 
OnClientClick="javascript:window.print();" />
 
Through Server Side 
 Normally v done through client side but some cases, example : only registered users are 
allowed this functionality then it's need a postback isit. 
 
protected void printButton_Click(object sender, EventArgs e)
 {
  check ur condition
   // yes
     btn_Print.Attributes.Add("onclick", "return printing()");
  else
   //no
  }

and on html page add this JavaScript function  

function printing()
        {
            window.print();
           
        }

Hope it helps u.
Stay tune...
Have a nice day... 'N happy Coding :)

No comments: