Click here to Skip to main content
15,174,572 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
<asp:LinkButton ID="lbnPrint" runat="server" class="msLinkButton" OnClientClick="CallPrint();"
                                TabIndex="9" Text="Print"></asp:LinkButton>

function CallPrint()
      var lbnCreatereport = document.getElementById('ctl00_ContentPlaceHolder_lbnCreatereport');
      if (lbnCreatereport != null)
  = 'none';
     var lbnSave = document.getElementById('ctl00_ContentPlaceHolder_lbnsave');

      if (lbnSave != null)
      { = 'none';
     var lbnCancel = document.getElementById('ctl00_ContentPlaceHolder_lbncancel');

     if (lbnCancel != null)
     { = 'none';

     var lbnSubmit = document.getElementById('ctl00_ContentPlaceHolder_lbnsubmit');

     if (lbnSubmit != null)
     { = 'none';
     var lbnPrint = document.getElementById('ctl00_ContentPlaceHolder_lbnprint');

     if (lbnPrint != null)
     { = 'none';
     var txtSDName = document.getElementById('ctl00_ContentPlaceHolder_txtSDName');

     if (txtSDName != null)
     { = 'none';
        txtSDName.disabled=false ;
        txtSDName .readOnly=true;

             var display_setting = "'', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=1,status=0,resizable'";
            var content_innerhtml = document.getElementById("printme").innerHTML;
            var document_print ="", "", display_setting);
            return false;

Hi, I tried on print linkbutton, I wrote the code using javascript for Print LinkButton. When clicking on the Print Linkbutton it's open the new window , The problem here is after opening the new window , the Main page is refreshing and lose data in main page,and also in new window open a message box , in that Print and cancel Buttons . when click on the cancel button and it refreshing the main page also.
I think , we wrote the javascript for print popup, why refreshing the main page when opening the new window and cancel button in new window.

Please any one help me
Updated 23-Jul-12 20:03pm

1 solution

A server control will surely postback on click. You need to use a HTML control instead

<input type="submit" value="Print"  önclick="return CallPrint();">


anchor tag
<a href="#Foo"  önclick="runMyFunction(); return false;">Do it!</a>
CH Guravaiah 20-Jul-12 7:23am
Based on Client requirement i am using Linkbutton in my page. how to prevent the postback of linkbutton.
bbirajdar 20-Jul-12 8:27am
Use a anchor html tag...Its the HTML control and will not postback...

Added a code sample in solution for anchor tag

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900