469,628 Members | 1,206 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,628 developers. It's quick & easy.

Print and Print Preview in ASP.Net 2.0

hi..
How will i use print and print preview option. I have to print only a part of a page.
for that i declare in a div and give that a id and then using java function to print that portion but my problem is that the page is directly printed and i am not getting the option of print preview.
How will it possible?Please give me suggestion
My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. code for aspx page
  2.  
  3. <head>
  4.  <script type="text/javascript">
  5.     function CallPrint(strid)
  6.     {
  7.      var prtContent = document.getElementById(strid);
  8.      var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
  9.      WinPrint.document.write(prtContent.innerHTML);
  10.      WinPrint.document.close();
  11.      WinPrint.focus();
  12.      WinPrint.print();
  13.      WinPrint.close();
  14.      prtContent.innerHTML=strOldOne;
  15.     }
  16.     </script></head>
  17.  
  18. <body>
  19. <div id="divPrint">
  20. ................
  21. </div>.........
  22. <asp:ImageButton ID="cmdPrint" runat="server" ImageUrl="~/Images/print.gif" OnClick="cmdPrint_Click" />
  23. ...............
  24. </body>
  25.  
  26.  
  27. and that the code i used in .aspx.cs page
  28.  
  29.  protected void cmdPrint_Click(object sender, ImageClickEventArgs e)
  30.     {
  31.         string contentId = "divPrint";
  32.         string javaScript = "<script language=JavaScript>CallPrint('" + contentId + "');</" + "script>";
  33.         RegisterStartupScript("PrintWindowScript", javaScript);
  34.     }
  35.  
  36.  
please help...
Feb 9 '08 #1
0 3521

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by ShaneO | last post: by
6 posts views Thread by CSharpguy | last post: by
9 posts views Thread by igotyourdotnet | last post: by
2 posts views Thread by Brad Pears | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.