Results 1 to 3 of 3

Thread: Passing session variable between two forms

  1. #1

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Passing session variable between two forms

    I've got two forms. The parent opens a kind of open file dialog box in the form of a web page. The child form consists of a listbox which gets populated with filenames, and a command button. I would like to pass the selected value back to the parent form. This is what I have so far:
    VB Code:
    1. 'Parent Form
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         RegisterStartupScript("ClientSideScript", "<script language=javascript>window.open('OpenFile.aspx', null, 'location=no;status=no;addressbar=no;toolbar=no,height=350,width=250')</script>")
    4.     End Sub
    5.  
    6.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.         Try
    8.             TextBox1.Text = Session("name").ToString()
    9.         Catch oEX As Exception
    10.             Console.WriteLine(oEX.ToString)
    11.         End Try
    12.     End Sub
    VB Code:
    1. 'Child Form
    2.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         Dim sfile As String = Dir("C:\Temp\*.xml", FileAttribute.Normal)
    4.         While sfile <> Nothing
    5.             sfile = sfile.Substring(0, sfile.IndexOf("_"c)) & ", " & sfile.Substring(sfile.IndexOf("_"c) + 1)
    6.             sfile = sfile.Substring(0, sfile.Length - 4).ToUpper
    7.             ListBox1.Items.Add(sfile)
    8.             sfile = Dir()
    9.         End While
    10.  
    11.     End Sub
    12.  
    13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    14.         Session("name") = ListBox1.SelectedValue
    15.         Server.Transfer("webform1.aspx")
    16.         RegisterStartupScript("ClientSideScript", "<script language=javascript>window.close();</script>")
    17.  
    18.     End Sub

    The problem is, the parent form reopens in the child form's browser after I pass the variable. I would really like the child form to close, and have the original parent form handle the variable.

  2. #2

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Passing session variable between two forms

    I was able to prevent the parent page from loading to the child browser by taking out the Server.Transfer line.
    My new question is, how can I make the parent window wait for the child window to close before declaring a string variable set to the session variable's value?

  3. #3

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Passing session variable between two forms

    Here's the code I used to force the postback.
    Code:
            RegisterStartupScript("ClientSideScript", "<script language=javascript>window.opener.document.forms[0].submit();window.close();</script>")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width