Is there anyone how to write the print function so that i can print out the web form with the web control contents.Here is the scenario , the web form i would like to print out have:

1.TextboxA.txt = "Sample1"
2.TextboxB.txt = "Sample2"
3.DropdownlistA.selectedIndex = "1"
4.CalendarA.


Please teach me how to write the print function in ASP.NET so that i can print out the web form with the result like this:

Name : Sample1
Age : Sample2
Sex : ValueB *(since the dropdownlist selected index is 1)
Date : CalendarA.

I had do some searching on the internet , most of them introduced the Javascript method to write the Print function.I tried , but it cannot print out the property of the web control.Please give me some help.

>but it cannot print out the property of the web control.Please give me some help.

Not sure about your question but what I understood that you want to print markup (tags) of web-page. You need to encode the html markup.

<!DOCTYPE html>

&lt;html&gt;
&gt;head&gt; &gt;/head&gt;
 &lt;p&gt;Hello World&lt;p&gt;
&lt;/html&gt;
<script type="text/javascript">
  print();
</script>

This is how i write it... Print.js

function printdiv(empno, name, recordDate,leavetype,emailnotify,duration,datedetail) {


    var employeeName = name;
    var employeeID = empno;
    var RecordDate = recordDate;
    var LeaveType = leavetype;
    var MailNotify = emailnotify;
    var LeaveDuration = duration;
    var DateDetail = datedetail;
    var headstr = "<html><head><title></title></head><body><h2>Test Print begin....<br/><br/>";
    var footstr = "<h2></body>";
    var newstr = "Testing";


    document.body.innerHTML = headstr + newstr + "Employee Name : " + employeeName + "<br/><br/>"
    + "Employee ID: " + employeeID + "<br/><br/>" + "Record Date : " + RecordDate + "<br/><br/>" + "Leave Type : " + LeaveType +
     "<br/><br/>" + "Email Notify : " + MailNotify + "<br/><br/>" + "Leave Duration : " + LeaveDuration + "<br/><br/>"
     +"Date Detail : "+DateDetail + "<br/><br/>"+footstr;
    
    window.print();

I have the codes written in my notebook. It doesn't include JavaScript. Is it okay if I explain using C# codes?

Oops. sorry. I have the codes of winforms not webforms

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.