Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi all,

in my application when i click on preview button then one pop up comes with print preview. there is print button in that pop up and when i click on that print button printing is done. all the things are working fine.

Now problem is that when i click on print button in print preview pop up the page behind pop up is redirecting to print preview page. i don't want to redirect it.

here is my code in jquery:

in this code when click on preview button this code runs:

C#
var strVal='';
function PreviewReport(WithPrint)
{
    var id;
    id = document.getElementById('ctl00_ContentPlaceHolder1_lblMessage');

    if (id != undefined)
    {
        strVal = id.innerHTML;


        if(strVal == "")
        {
        return false;
        }
        else
        {

            if (WithPrint==1)
            {
                $("#PrintingDiv").load('ViewReportNew.aspx', { "strVal": strVal });
                //$("#PrintingDiv").load('ViewReportNew.aspx', { "strVal": strVal }).dialog({modal:true,width:780,height:550});

            }
            else
            {
                $("#PrintingDiv").load('ViewReportNew.aspx', { "strVal": strVal }).dialog({modal:true,width:780,height:550});

            }

        }
    }
    DPrint.style.display = 'block';
    return false;
}

function PrintReport()
{
//var strVal;
//strVal = document.getElementById('ctl00_ContentPlaceHolder1_lblMessage').innerHTML;
//window.open('ViewReportNew.aspx?strVal=' + strVal , '_blank', 'width=780,height=550,scrollbars=1');
//return false;

PreviewReport(0);

 var prtContent = document.getElementById(strid);
 var strOldOne = document.body.innerHTML;
 var WinPrint = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=1,status=1');

 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 document.body.innerHTML = strOldOne;

    return false;
}



on preview page this code runs:

XML
<script language="javascript">
function CallPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=1,status=1');
 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 prtContent.innerHTML=strOldOne;
 this.close();
}

    </script>


any idea..
Posted

1 solution

Use chrome to step through your code to see where it's not doing what you want. I don't see any redirect code in what you've presented here, so I don't see why it would redirect, unless the issue is that you need to return false to stop it from doing so.
 
Share this answer
 
Comments
kk2014 1-Aug-12 9:16am    
where i have to write return false;?
Christian Graus 1-Aug-12 15:55pm    
If your client side method returns false, your server side postback will not run.

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