Click here to Skip to main content
14,694,027 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)
      {
           lbnCreatereport.style.display = 'none';
      } 
     var lbnSave = document.getElementById('ctl00_ContentPlaceHolder_lbnsave');

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

     if (lbnCancel != null)
     {
       lbnCancel.style.display = 'none';
     }

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

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

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

     if (txtSDName != null)
     {
        txtSDName.style.border = '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 = window.open("", "", display_setting);
            document_print.document.open();
            document_print.document.write(content_innerhtml);
            document_print.document.write('</body></html>');
            document_print.print();
            document_print.document.close();
            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
Posted
Updated 23-Jul-12 20:03pm
v7

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();">
                                 name="Print"/></input>



OR

anchor tag
<a href="#Foo"  önclick="runMyFunction(); return false;">Do it!</a>
   
v2
Comments
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