• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1274
  • Last Modified:

ASP.NET (closing popup window & passing session variable)





I have an .aspx page (main.aspx) with a button that opens up a popup window (popup.aspx) using the code below.

Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click

            Dim popupScript As String = "<script language='javascript'>" & _
             "window.open('popup.aspx', 'CustomPopUp', " & _
             "'width=640, height=470, menubar=no, resizable=no, scrollbars=no')" & _
             "</script>"
            RegisterStartupScript("PopupScript", popupScript)
End Sub

Here is my question.

The popup window is a survey where the user answers some questions. (True/False & multiple choice). I have some code that builds a string of characters based upon the responses. String consists of 1's, 2's 3's, & 4's and is held in a session variable.

When the survey is complete, I would like to close window (popup.aspx) and pass this session variable back to (main.aspx).

Any suggestions or answers on the best way to do this?

Thanks,
Mike
0
MichaelVB
Asked:
MichaelVB
1 Solution
 
YZlatCommented:
this javascript function will close your popup window and load parent window again:

function loadinparent(url, closeSelf){
      self.opener.location = url;
      if(closeSelf) self.close();
      }

put this function in the <head> section of the page of your popup window.

Put a button on your popup page that will close it:
<asp:Button id="myButton" text="Close Me" runat="server" />

Then in Page_Load procedure put the following code:

myButton.Attributes.Add("onclick", "javascript:loadparent('main.aspx'), this);")

0
 
MichaelVBAuthor Commented:
YZlat,

Thanks for your help, for some reason this is not working though.

// This is what I have in page OnScreen2.aspx which is the PopUp window:

<HTML>
  <HEAD>
    <title>Test Presentation</title>
   
    <SCRIPT language="javascript">
      function loadinparent(url, closeSelf)
      {
       self.opener.location = url;
       if(closeSelf)self.close();
      }
     </SCRIPT>
</HEAD>

In the body I have:
<ASP:BUTTON id="btnSSupervisor" runat="server" text="Supervisor"></ASP:BUTTON>

In codeBehind page (OnScreen2.aspx.vb) I have this

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    btnESupervisor.Attributes.Add("onclick", "javascript:loadinparent('OnScreen.aspx'), this);")
    ' actual code automatically underlines     _______________________________________  this part here
End Sub

// OnScreen.aspx is the main window that opens the PopUp window...

The only thing that seems to  happen when I click on btnESupervisor is the screen refreshes but nothing else?
Any ideas on what I may be doing wrong here?

Thanks again,
Mike
0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now