| | |
how to print the contents of text box
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 10
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
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
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 10
This code should manage your printing with asp.net. It's a piece of javascript

ASP.NET Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- function printTextBox_Text(elementId) { var textboxText = document.getElementById(elementId); var windowUrl = 'about:blank'; var windowName = 'Print' + new Date().getTime(); var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0'); printWindow.document.write(textboxText .value); printWindow.document.close(); printWindow.focus(); printWindow.print(); printWindow.close(); } // --> </script>
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 10
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
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
ASP.NET Syntax (Toggle Plain Text)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim sPrintScript As System.Text.StringBuilder = New System.Text.StringBuilder sPrintScript.Append("<script type='text/javascript'>").AppendLine("") sPrintScript.Append("<!--").AppendLine("") sPrintScript.Append("function printText(elementId)").AppendLine("") sPrintScript.Append("{").AppendLine("") sPrintScript.Append("var printContent = document.getElementById(elementId);").AppendLine("") sPrintScript.Append("var windowUrl = 'about:blank';").AppendLine("") sPrintScript.Append("var windowName = 'Print' + new Date().getTime();").AppendLine("") sPrintScript.Append("var sTextToPrint = printContent.innerHTML;").AppendLine("") sPrintScript.Append("var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');") sPrintScript.AppendLine("") sPrintScript.Append("printWindow.document.write(sTextToPrint);").AppendLine("") sPrintScript.Append("printWindow.document.close();").AppendLine("") sPrintScript.Append("printWindow.focus();").AppendLine("") sPrintScript.Append("printWindow.print();").AppendLine("") sPrintScript.Append("printWindow.close();").AppendLine("").Append("}").AppendLine("") sPrintScript.Append("// -->").AppendLine("") sPrintScript.Append("</script>") If Not ClientScript.IsClientScriptBlockRegistered("printText") Then _ ClientScript.RegisterClientScriptBlock(Me.GetType(), "printText", sPrintScript.ToString) Button1.Attributes.Add("onclick", String.Format("return printText('{0}');", Me.TextBox1.ClientID)) End Sub
![]() |
Similar Threads
- How to print contents inVB.Net (VB.NET)
- copying the contents of richtext box with same font (C#)
- using rich text box to print its contents (C#)
- read-delete lines from a text file (PHP)
- VB Advanced TEXT BOX problems (Visual Basic 4 / 5 / 6)
- i have this on my XP desktop:TROJAN-SPY.HTML.SMITFRAUD.c (Viruses, Spyware and other Nasties)
- Trojan-Spy.HTML.Smitfraud.c (Viruses, Spyware and other Nasties)
- Want to use radio button or menu bar instead of combo box (Java)
Other Threads in the ASP.NET Forum
- Previous Thread: Master/Detail DropDownList and DataGrid
- Next Thread: error while i am writing the code to file upload
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






