how to print the contents of text box

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Aug 2008
Posts: 27
Reputation: sancti is an unknown quantity at this point 
Solved Threads: 0
sancti sancti is offline Offline
Light Poster

how to print the contents of text box

 
0
  #1
Dec 8th, 2008
hi all,
I am developing a web application. I have loaded some block of text into the text box. Now i want to print only the contents of the text box.Can anybody help me regarding since i am new to asp.net

thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: how to print the contents of text box

 
0
  #2
Dec 8th, 2008
Print? I guess you mean print on the screen?

Did you check the HttpContext.Current.Response object?

Regards,
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 27
Reputation: sancti is an unknown quantity at this point 
Solved Threads: 0
sancti sancti is offline Offline
Light Poster

Re: how to print the contents of text box

 
0
  #3
Dec 8th, 2008
hi,
no i have not used HttpContext.current......
If i use that, will it be possible to print the contents of text box in the sameway as i entered into the text box. Can u please explain me briefly how to use that..
thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: how to print the contents of text box

 
0
  #4
Dec 8th, 2008
Hi :=)

Do you want to change the screen during typeing the text in the textbox?
You have to notice that the scripts you write (in the code-behind-page or in the page itself) are serverside executed. Which means that you have to implement some kind of redirection. The redirection has been standarized within the textbox by means of the autopostback option. This, in combination with the TextChange() event is a worse combination because after each keypress the page will be posted back.....
The LostFocus() event gives a much better performance on this but the page still have to make a roundtrip to the server in able to execute the scripts.....

What exactly are you trying to acchieve?

Regards,
Richard
The Netherlands
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 27
Reputation: sancti is an unknown quantity at this point 
Solved Threads: 0
sancti sancti is offline Offline
Light Poster

Re: how to print the contents of text box

 
0
  #5
Dec 8th, 2008
hi Richard,
Thank you for your reply.Actually i have loaded some block of text into the text box with particular line at particular position. Now i want to print that contents of text box by pressing the print button.Can u please help me to solve this
thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: how to print the contents of text box

 
0
  #6
Dec 8th, 2008
This code should manage your printing with asp.net. It's a piece of javascript

  1. <script type="text/javascript">
  2. <!--
  3. function printTextBox_Text(elementId)
  4. {
  5. var textboxText = document.getElementById(elementId);
  6. var windowUrl = 'about:blank';
  7. var windowName = 'Print' + new Date().getTime();
  8. var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
  9.  
  10. printWindow.document.write(textboxText .value);
  11. printWindow.document.close();
  12. printWindow.focus();
  13. printWindow.print();
  14. printWindow.close();
  15. }
  16. // -->
  17. </script>
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: how to print the contents of text box

 
0
  #7
Dec 8th, 2008
I've worked it out to an example for you....

Place 1 textbox control on your page, make it multiline and insert the below stated code in the code-behind page.

Regards,
Richard
The Netherlands
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2. Dim sPrintScript As System.Text.StringBuilder = New System.Text.StringBuilder
  3. sPrintScript.Append("<script type='text/javascript'>").AppendLine("")
  4. sPrintScript.Append("<!--").AppendLine("")
  5. sPrintScript.Append("function printText(elementId)").AppendLine("")
  6. sPrintScript.Append("{").AppendLine("")
  7. sPrintScript.Append("var printContent = document.getElementById(elementId);").AppendLine("")
  8. sPrintScript.Append("var windowUrl = 'about:blank';").AppendLine("")
  9. sPrintScript.Append("var windowName = 'Print' + new Date().getTime();").AppendLine("")
  10. sPrintScript.Append("var sTextToPrint = printContent.innerHTML;").AppendLine("")
  11. sPrintScript.Append("var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');")
  12. sPrintScript.AppendLine("")
  13. sPrintScript.Append("printWindow.document.write(sTextToPrint);").AppendLine("")
  14. sPrintScript.Append("printWindow.document.close();").AppendLine("")
  15. sPrintScript.Append("printWindow.focus();").AppendLine("")
  16. sPrintScript.Append("printWindow.print();").AppendLine("")
  17. sPrintScript.Append("printWindow.close();").AppendLine("").Append("}").AppendLine("")
  18. sPrintScript.Append("// -->").AppendLine("")
  19. sPrintScript.Append("</script>")
  20. If Not ClientScript.IsClientScriptBlockRegistered("printText") Then _
  21. ClientScript.RegisterClientScriptBlock(Me.GetType(), "printText", sPrintScript.ToString)
  22. Button1.Attributes.Add("onclick", String.Format("return printText('{0}');", Me.TextBox1.ClientID))
  23. End Sub
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: how to print the contents of text box

 
0
  #8
Dec 8th, 2008
the solution is simple, just open a new window with the content of that textbox using javascript.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: how to print the contents of text box

 
0
  #9
Dec 10th, 2008
hmm... did you read my last post serkansendur?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 27
Reputation: sancti is an unknown quantity at this point 
Solved Threads: 0
sancti sancti is offline Offline
Light Poster

Re: how to print the contents of text box

 
0
  #10
Dec 10th, 2008
hi richard,
I think the code u have written is VB.NET, Can u please send the code in C#.

thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC