-1

I have a form with a print button, when clicked, opens up a separate browser tab that displays a Sql Server Reporting Services report. I am also passing two variables to this separate report page.

Protected Sub btnPrint_Click(sender As Object, e As EventArgs) Handles   btnPrint.Click

    Dim VID As Integer
    Dim SID As Integer
    Dim QueryString As String
    Dim dc As New VehicleDataContext(db.ConnectionString)

    Dim oReportPath = From rpt In dc.ReportLists _
                      Where rpt.ReportName = "Vehicle Service Record" _
                      Select rpt.ReportPath

    Dim sURL As String = "ReportViewer.aspx"
    Session.Add("ReportPath", oReportPath.First)

    VID = CInt(Session("VId"))
    SID = CInt(Session("SID"))

    QueryString = "ReportViewer.aspx?ID=" & VID
    QueryString = QueryString & "&SID=" & SID

    Response.Redirect(QueryString)

The report opens up without a problem, but the difficulty I am having is with the JavaScript.

<script type = "text/javascript">

function SetTarget() {

    document.forms[0].target = "_blank";
}

</script>

<script type = "text/javascript">

 var ResetTarget = function () {

   document.forms[0].target = "_self";

        }
</script>

On the OnClientClick event for this button, I added the code to force the report to open in a new tab. The second JavaScript function is to reset the application back to default behavior. I placed a call to this code under the "Close" button, but I realized that clicking other buttons or links on the web page will keep opening up my form in new browser tabs, which I don't want.

Is there a way of calling this ResetTarget script once the print button code has successfully completed so that other page events on this form don't keep opening up new windows?

Thanks in advance.

stuartm
  • 15
  • 1
  • 6
  • I saw those other posts before I posted this, but they didn't address the exact problem I was having – stuartm May 12 '16 at 13:42

1 Answers1

0
function SetTarget() {

    document.forms[0].target = "_blank";
    setTimeout(function(){document.forms[0].target = "_self";},300);
}

Is it acceptable?

Alex Kudryashev
  • 9,120
  • 3
  • 27
  • 36