Fire a javascript function from vb.net

  • Thread starter Thread starter Cesar Zam
  • Start date Start date
C

Cesar Zam

Hello
I try to fire a javascript function from vb.net. This function will
create a popup window and inside of it display a crystal report: this
is what I got so far

Private Sub btPost_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btPost.Click
Dim objCash As New Processes.clsCashReceipts()
ReferenceNo = objCash.postToGL(txtBatch.Text,
Trim(txtPastBatchID.Text))
If ReferenceNo > 0 Then
postSucceeds() 'data save was OK
Session("ReferenceNo") = ReferenceNo
displayMessage("Posted successfully. Preparing report
please wait...", True)
PrintReports(ReferenceNo)
Else
displayMessage("Posting failed", False)
End If
clearCashHeaderSc()
End Sub


Private Sub PrintReports(ByVal ReferenceNo As Integer)
Dim sb As String
Dim xRefNo As String = Trim(Str(ReferenceNo))

sb = ControlChars.CrLf & "<script language=javascript> " &
ControlChars.CrLf
sb = sb + "function openReport1(xRefNo)" & ControlChars.CrLf
sb = sb + "{ " & ControlChars.CrLf
sb = sb + "var wpopup; " & ControlChars.CrLf
sb = sb + "var intViewOption,intOnlineOffline; " &
ControlChars.CrLf
sb = sb + "document.frmCash.btRep.disabled=true" &
ControlChars.CrLf
sb = sb + "intViewOption = '2';" & ControlChars.CrLf
sb = sb + "intOnlineOffline = '1';" & ControlChars.CrLf
'sb = sb + "loc =
'../Reports/ReportOutput.aspx'+'?RptName=CashReceiptsEdit&OpenMode='+
intViewOption +'&ReportViewing='+ intOnlineOffline +'&strBatchNo=' +
document.frmCash.txtBatch.value +'&strBatchID=' +
document.frmCash.txtPastBatchID.value;"
sb = sb + "loc='../Reports/ReportOutput.aspx'+'?RptName=ReprintPostingReport&OpenMode='+
intViewOption +'&ReportViewing='+ intOnlineOffline +'&ReferenceNum='+
xRefNo ;" & ControlChars.CrLf
sb = sb + "if (!wpopup || wpopup.closed)" & ControlChars.CrLf
sb = sb + "{" & ControlChars.CrLf
sb = sb + "wpopup=window.open(loc,'nofr_address','resizable=yes,scrollbars=no,toolbar=no,menubar=yes,location=no,scrollbars=yes,resizable=yes');"
& ControlChars.CrLf
sb = sb + "wpopup.focus();" & ControlChars.CrLf
sb = sb + "if (wpopup.opener == null){wpopup.opener = self;}"
& ControlChars.CrLf
sb = sb + "}" & ControlChars.CrLf
sb = sb + "else" & ControlChars.CrLf
sb = sb + "{" & ControlChars.CrLf
sb = sb + "wpopup.focus();" & ControlChars.CrLf
sb = sb + "}" & ControlChars.CrLf
sb = sb + "};" & ControlChars.CrLf
sb = sb + "</script>"

' If Not IsStartupScriptRegistered("Startup") Then
' RegisterStartupScript("Startup", sb.ToString())
' End If
' If (Not
IsClientScriptBlockRegistered("clientScript")) Then
' RegisterClientScriptBlock("clientScript",
sb.ToString)
' End If
If Not IsStartupScriptRegistered("PrintReports") Then
RegisterStartupScript("PrintReports", sb.ToString())
End If

End Sub

The function is created in the client side but it can not be fired.
any Help will be really appreciate
 
take it simple first to see if you have a script error
Response.Write("<script>alert('hello, world')</script>");
then expand on that, it is normally a script error
 
Back
Top