Solved

Window.Close NOT working???

Posted on 2013-06-04
10
347 Views
Last Modified: 2013-06-09
OK I've spend way too much time trying to figure this out and now I need some help!

I open a PopUp Window with a Crystal Report:
        Dim PopUpScript As String = "<script language='javascript'>" + "window.open('CrystalReportViewer.aspx?SiteID=" & ddl_Sites.SelectedValue & "&ClientID=" & ddl_Clients.SelectedValue & "&BDate=" & txt_StartDate.Text & "&EDate=" & txt_EndDate.Text & "&Status=" & ddl_Status.SelectedValue & "&Type=" & ddl_LockboxType.SelectedValue & "'" & ",'','width=1000px,height=800px, status=yes, resizable=yes, scrollbars=yes, toolbar=yes,location=yes,menubar=yes').focus();</script>"
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopUpWindow", PopUpScript, False)


Then I have a button on the PopUp to close the window:
    Protected Sub cmd_ClosePage_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        CrystalReportSource.Dispose()
        SQLDataSource.Dispose()

        Dim CloseWindowScript As String = "<script language='javascript'>" + "window.close();</script>"
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "CloseWindow", CloseWindowScript, False)
    End Sub

This doesn't work...it clears out the Crystal Report but the window is still open with my buttons at the top hit close again nothing???

Thanks,
Mark
0
Comment
Question by:smithmrk
10 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 39219830
Are you saying when you close the Crystal window you want the app the terminate or that the close button on the app no longer works?

mlmcc
0
 

Author Comment

by:smithmrk
ID: 39219846
See attached PDF with screen shots!

Mark
ReportRuns.pdf
0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 39219848
If all you need to do is close the window when the button is clicked, do not use code behind. Add your javascript to the button's client-side onclick event:
<button>.Attributes.Add("onclick", "window.close();")
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39219851
Are you clicking the close button shown or the close/X in the report window?

mlmcc
0
 

Author Comment

by:smithmrk
ID: 39219855
Close Button
If I click the X then YES the window disappears...I want the same affect with the Close Button.

Mark
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Expert Comment

by:xFDSx
ID: 39219875
Remove the disposes.... or move them below last line...
Replace false at end with true...
Page.ClientScript.RegisterStartupScript(Me.GetType(), "CloseWindow", CloseWindowScript, False)

Oh and your closewindowscript just needs to be "Window.Close()"
0
 

Author Comment

by:smithmrk
ID: 39219883
Nope same results!

Mark
0
 

Accepted Solution

by:
smithmrk earned 0 total points
ID: 39220171
OK, after about 6 hours of working on this taking your suggestions and google...I figured it out!

Instead of Page.ClientScript.RegisterStartupScript
I needed this:

ScriptManager.RegisterStartupScript(Me, Me.GetType(), "CloseWindow", "window.close();", True)

ScriptManager NOT Page.ClientScript.RegisterStartupScript!

Finally!!!

Thanks for you help!
Mark
0
 

Author Comment

by:smithmrk
ID: 39220182
Correction...I needed to have a Javascript Function on the page and call it using the ScriptManager:

Call:
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "CloseWindow", "closeWindow();", True)

Function:
function closeWindow()
{
     window.close();
}
0
 

Author Closing Comment

by:smithmrk
ID: 39232749
Figured it out on my own!

Mark
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now