Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET + Popup window return value + Javascript

Posted on 2004-08-02
18
Medium Priority
?
1,091 Views
Last Modified: 2008-02-07
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?
0
Comment
Question by:dkilby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
  • +1
18 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11696656
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
 
LVL 9

Expert Comment

by:crescendo
ID: 11696851
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
 

Author Comment

by:dkilby
ID: 11696873
Crescendo, How would i do that though
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:dkilby
ID: 11697104
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
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11697242
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
 

Author Comment

by:dkilby
ID: 11697324
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
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11697443
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
 

Author Comment

by:dkilby
ID: 11697487
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
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11697587
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
 
LVL 9

Expert Comment

by:crescendo
ID: 11697743
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
 
LVL 9

Expert Comment

by:crescendo
ID: 11697749
PS It's straight HTML and Javascript so should work with your page easily.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11697979
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
 

Author Comment

by:dkilby
ID: 11699123
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
 
LVL 9

Expert Comment

by:crescendo
ID: 11699137
Have you put the onFocus= code in the BODY tag?
0
 

Author Comment

by:dkilby
ID: 11699151
<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
 
LVL 9

Expert Comment

by:crescendo
ID: 11699316
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
 
LVL 9

Accepted Solution

by:
crescendo earned 2000 total points
ID: 11701527
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
 
LVL 2

Expert Comment

by:dlarlick
ID: 11714797

  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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

688 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