Dennis J Olson on Thu, 26 Sep 2013 19:46:41
I have an application with two Divs. One Div is visible if the user has Admin capability, and a different one is visible if the user does not.
In the first Div is an Editor control. Text data is pulled from the database and loaded into the editor text-entry area. In the second Div is a simple Label control which receives that same data.
I have been tasked with adding a PRINT button such that when clicked, a printer dialog opens, and when they click Print in that dialog box (after potentially selecting a different printer), the data in whichever control/Div is visible needs to be sent to the printer.
I may NOT open up another app such as Notepad or Word. I have to send the data directly from the control. I am very new to C#, and don't have a clue how to do this. (However, I have many years in VB.) There is a separate PRINT button for each Div, but they both use the same OnClick event code.
Any insight into this would be hugely appreciated.
tnw on Thu, 26 Sep 2013 19:52:25
Please take a look at this resource about printing. It should get you started.
Caillen on Fri, 27 Sep 2013 07:45:22
Please check this thread:
The third solution using JQuery to print in this link seems to be good for you.
In another thread, similar solution is given:
Also an example from code project here:
I hope it helps.
Dennis J Olson on Fri, 27 Sep 2013 21:06:16
That being said, I have a different issue now. the text I need to print is the .defaultValue of a hidden control on the web page. there is no DIV in which this code resides, so there is nothing in any innerHTML attribute for me to harvest.
Now, the data that's in the control will have HTML embedded in it, as it will be a "page" of text. But being in the defalutValue of the control, when I fetch that data and place it onto my temporary HTML page for printing, the markup shows as TEXT. It doesn't actually render when dropped onto the in-progress page.
Does anyone know how I can force the markup to render? If I can do that, I will have successfully completed this task.
Caillen on Mon, 07 Oct 2013 05:14:24
Assuming your hidden control's id is Hidden_ID, use document.write method to write the html content to the new page to print: