ASP.NET + Popup window return value + Javascript

I have a popup window that has a flash movie, at the end of the flash movie i have a close window button, using javascript.  Is there anyway of sending a value back to the main ASP.net so it will refresh or reload?
dkilbyAsked:
Who is Participating?
 
crescendoCommented:
dkilby:

I asked around and the answer is so simple. In the new window, where you use Javascript to close the window, put

    opener.location.href=opener.location.href;
    window.close();

This will tell the original window to reload itself. If you want to be really careful and check that the original window still exists, change the first line to

    if (window.opener) opener.location.href=opener.location.href;

Hope this does it.
0
 
DotNetLover_BaanCommented:
yes you can send data to the parent page from the popup page.
For example, I have a little calendar image on a page, clicking on which pops up a a calender window. When a date is selected from the calendar, it sends the date back to the main page and display the date in a textBox.

My Calender Page:
=============

Public Class PopUpCalendar
    Inherits System.Web.UI.Page
    Protected WithEvents control As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents calDate As System.Web.UI.WebControls.Calendar

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        control.Value = Request.QueryString("textbox").ToString()
    End Sub

    Private Sub calDate_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calDate.SelectionChanged
        Dim strScript As String = "<script>window.opener.document.forms(0)." + control.Value + ".value = '"
        strScript += calDate.SelectedDate.ToString("MM/dd/yyyy")
        strScript += "';self.close()"
        strScript += "</" + "script>"
        RegisterClientScriptBlock("anything", strScript)
    End Sub
End Class
=================================================

In the main page, I am using:

onclick="window.open('popupCalendar.aspx?textbox=TB_Date','cal','width=355,height=200,left=270,top=180')" href="javascript:;">

** "TB_Date" is the TextBox control where I want to display the selected date.

-Baan
0
 
crescendoCommented:
One way would be to put an onFocus event handler on the "parent" page, so that when it got the focus, it checked if the window was still open, and took action accordingly.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
dkilbyAuthor Commented:
Crescendo, How would i do that though
0
 
dkilbyAuthor Commented:
Baan

If i just want to send a value back when the close window button is pressed, what code do i need?  right now all i have is window.close.  I kind of understand what you have but not fully.

Thanks for the help
0
 
DotNetLover_BaanCommented:
ok...
Go to the event handler for that button... and add this

        Dim strScript As String = "<script>window.opener.document.forms(0)." + control.Value + ".value = '"
        strScript += your data that you want to send back
        strScript += "';self.close()"
        strScript += "</" + "script>"
        RegisterClientScriptBlock("MyScript", strScript)

=====
How are you showing the popup... ?  I need more information to tell you exactly what you need
-Baan
0
 
dkilbyAuthor Commented:
to get the popup to come up this is the script.

btn_playNow.Attributes.Add("OnClick", "javascript:window.open('Game/testclose.htm','Played','width=500,height=400,menubar=no,resizable=no,left=150,top=150')")


the code to close the window is Flash and the code is

getURL("javascript:close()");
0
 
DotNetLover_BaanCommented:
Excellent.... I need a little more info. Where do you want to send the data value from the popup window ?
For example;  get a textbox in your main page, you can make it invisible. Say you have the textbox (TB1), then...
It should be like this...
btn_playNow.Attributes.Add("OnClick", "javascript:window.open('Game/testclose.htm?textbox=TB1','Played','width=500,height=400,menubar=no,resizable=no,left=150,top=150')")

In the Page_Load of the PopUp page, get the control name...

Dim Ctrl As String
ctrl =  Request.QueryString("textbox").ToString()

Then, when you are closing the form, just add the script (In here, I am assuming that you have a btn, clickin on which will close the PopUp page and send the value):
So inside the Button's Clicked event...
        Dim strScript As String = "<script>window.opener.document.forms(0)." + ctrl + ".value = '"
        strScript += your data that you want to send back
        strScript += "';self.close()"
        strScript += "</" + "script>"
        RegisterClientScriptBlock("MyScript", strScript)

-Baan
0
 
dkilbyAuthor Commented:
I want to send the data value back to the main page, the problem is the Close Window is in Flash, i can not add the asp.net script in flash, or is the script for the button click event actionscript?
0
 
DotNetLover_BaanCommented:
Hmm... I see,  it is an html form, not an ASP/ASPX Webform. Can you access the CLOSE event of that form or the flash object?
wait... can you use session variables ? I am not sure if you can...
-Baan
0
 
crescendoCommented:
Here's the javascript, modify it for your own needs. It's a whole web page you can test with. When you click the button, it opens Google in a new window, if you close Google and go back to the original page, it detects the closure and opens Microsoft. Simply substitute your own sites/pages.

<html>
<head>
<title>This is the opening page</title>
</head>

<script Language=JavaScript>

  var win = null;
  var nms = "Neil is initialised";

  function butOpenWin_onclick()
  {
    win = window.open("http://www.google.co.uk", "myWindow","resizable=yes");
  }

  function gotFocus()
  {
    if (win && win.closed) location.href = "http://www.microsoft.com";
  }
</script>


<body onfocus="gotFocus()">
<input type="button" value="Open" onClick="butOpenWin_onclick()">
<p>Some text to click in............</p>
<p>Some text to click in............</p>
<p>Some text to click in............</p>
<p>Some text to click in............</p>
<p>Some text to click in............</p>
<p>Some text to click in............</p>
<p>Some text to click in............</p>
<p>Some text to click in............</p>
<p>Some text to click in............</p>
<p>Some text to click in............</p>
</body>
0
 
crescendoCommented:
PS It's straight HTML and Javascript so should work with your page easily.
0
 
crescendoCommented:
And if you simply want to reload the page, replace

    location.href = "http://www.microsoft.com";

with

    window.location.reload();

PS ignore the "Neil is initialised" bit - that was left in from testing!
0
 
dkilbyAuthor Commented:
Crescendo, i tried the code and it worked in a html button, i tried it in a ASP.NET button and can not get it to work.

I have the javascript at the top of the page and the onFocus in the body tag,  I have added this code to the asp.net button, it opens the window no problem, but when i close the window nothing happens.  Any suggestions.

                btn_playNow.Attributes.Add("OnClick", "javascript:butOpenWin_onclick()")
0
 
crescendoCommented:
Have you put the onFocus= code in the BODY tag?
0
 
dkilbyAuthor Commented:
<body onfocus="gotFocus()">  

if i put a HTML button on the same page it works,  i really need to use a ASP.NET button if possible
0
 
crescendoCommented:
I think it is because the ASP:Button is causing a postback, and that is causing the var "win" to be reinitialised, so it can't tell if the window is open or not when it gets the focus.

This means that you can't do anything with the first page until the second page closes. I'll see if I can find a workaround.
0
 
dlarlickCommented:

  Check out the following article

  "PopUp the .NET Way.."

  http://www.dotnetjohn.com/articles.aspx?articleid=88 

  This article talks about using a popup for window for just about any control you would desire.

   There is a corresponding article Create a Popup calendar for ASP.NET forms that does somewhat the same thing (on dotnetjohn) that is done using jscript. (if i remember correctly)

  -DLARLICK

 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.