Solved

Window.Close NOT working???

Posted on 2013-06-04
10
354 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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