Solved

Window.Close NOT working???

Posted on 2013-06-04
10
351 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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.

770 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