Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:16:40+00:00 2026-06-15T03:16:40+00:00

I have a function to print the content of a div. Let me share

  • 0

I have a function to print the content of a div. Let me share my aspx markup.

<div>
<div id="printarea" runat="server">
</div>
<asp:Button ID="btnPrint" runat="server" Text="Print Div" OnClick="btnPrint_Click" />

In the OnClick event innerhtml is set to the div printarea. The code is:

 protected void btnPrint_Click(object sender, EventArgs e)
    {

        string divText = GenerateInPatientBill();// "content you want to print";
        printarea.InnerHtml = divText;

        ScriptManager.RegisterStartupScript(this, Page.GetType(), "script", "PrintDiv(" + printarea.ClientID + ");", true);
    }

I need to pass the clientid of printarea div to the javascript function and get it printed. The javascript function used is

 function PrintDiv(printarea1) {
    alert($("#" + printarea1 + ""));
    var printContent = $("#" + printarea1 + "").html();
    alert(printContent);
    var popupWin = window.open('', '_blank', 'width=300,height=400,location=no,left=200px');
    popupWin.document.open();
    popupWin.document.write(printContent);
    popupWin.document.close();
    popupWin.focus();
    popupWin.print();
    popupWin.close();
}

Am getting javascript syntax error at line 2. Please help me on this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:16:41+00:00Added an answer on June 15, 2026 at 3:16 am

    Try this code below.

    function printDiv(DivIdToPrint) 
    { 
      var divToPrint= document.getElementById('DivIdToPrint'); 
      var newWin=window.open('','Print-Window','width=100,height=100'); 
      newWin.document.open(); 
      newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>'); 
      newWin.document.close(); 
      setTimeout(function(){newWin.close();},10); 
    }
    

    This JavaScript will open a new window with the content of the div, will print it and then will close that window. Last line, this is a must to set a timeout there, Otherwise in IE window will get closed before printing happens.

    Else you can use a jQuery plugin

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function to print database table to an array like this
hi i have a function that get information from xml data and print markers
say I have this class: class animal { function noise() { print 'woof'; }
Assume I have the function: function name_the_paramlist(varargin) % Print out varargin exactly how it
I have a sample class where I need to specialize the Print function if
Say I have a decorator which causes the function to print out any exceptions
I have a foreach function which permits me to print fields in a database,
I have this piece of code in a function. I want to print the
I have the following code function exibirDialog(div) { $(#divDialogo).ready(function() { $(#divDialogo).dialog({ open: function() {
I have a function like: uiModal.simpleModal('<p>This is some content</p>'); Which should call a modal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.