Solved

Window.Close NOT working???

Posted on 2013-06-04
10
349 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

16 Experts available now in Live!

Get 1:1 Help Now