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

Update Parent window controls with child window values

I have an asp.net application that opens a new window and passes 2 parameters to it as follows:

Dim strOpen As String = "<script>window.open('attachment.aspx?UID=" & Session("UID") & "&section=discussion','Attach','left=20,top=20,width=500,height=340,scrollbars=0,toolbar=0,status=0,resizable=0');</script>)"
        Me.RegisterStartupScript("WOpen", strOpen)

The child window has three file fields on it.  I want to be able to capture the values from the file fields and pass them to <asp:labels on the parent form when the child form is closed.

Thanks in advance.
0
tim_chamberlain
Asked:
tim_chamberlain
2 Solutions
 
cyberdevil67Commented:
Hi tim_chamberlain,

 try this in you popup window

    opener.document.getElementById["Fieldname"].value = "Andrew";

 but change the Javascript code above to use the formfield you wish to move over to the window.

Cheers!
0
 
tim_chamberlainAuthor Commented:
Hi cyberdevil67,

I'm getting an error using this function:

function CloseWindow()
{
opener.document.getElementById["lblAtt1"].value = document.Form1.fileAtt1.value;
window.close();
}

saying opener.document.getElementById["lblAtt1"] is Null or not an object.  The Form that contains the control lblAtt1 is an ASP.NET form i.e. runat="server" if that makes any difference.
0
 
cyberdevil67Commented:
try

opener.document.getElementById("lblAtt1").value = document.getElementbyId("fileAtt1").value;

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cyberdevil67Commented:
or

parent.document.getElementById("lblAtt1").value

0
 
tim_chamberlainAuthor Commented:
Still no luck.  Using the following code I no longer get an error but the parent form doesn't update.  I'm trying to update the text value of an asp label control:

function CloseWindow()
{
opener.document.getElementById("lblTest").text = document.Form1.fileAtt1.value;
self.opener.location=self.opener.location.href;
self.close();

}

parent.document causes the error described above.  I've also checked that document.Form1.fileAtt1.value is returning a valid value (which it is).

Thanks again.
0
 
cyberdevil67Commented:
Did you look at the = and what I also posted after that?
0
 
tim_chamberlainAuthor Commented:
Yes I did.

If I use this:
opener.document.getElementById("lblTest").text (or .value) = document.getElementbyId("fileAtt1").value; I get error: "object does not support this property or method".

If I use this:
parent.document.getElementById("lblTest").text (or .value) = document.getElementbyId("fileAtt1").value;

or:
parent.document.getElementById("lblTest").text = document.Form1.fileAtt1.value;

I get error: "parent.document.getElementById(...) is null or not an object"

Whereas this:
opener.document.getElementById("lblTest").text (or .value) = document.Form1.fileAtt1.value; I get no error but the parent form doesn't update.

I must be missing something.
0
 
archrajanCommented:
Can u post the view source?
0
 
cyberdevil67Commented:
This works for me...

parent.document.getElementById("lblTest").value = document.getElementById("fileAtt1").value;

Here is my code

index.htm
-----------
<form action="andrew.htm" method="post">
 <input type="text" name="test" value="Test">
</form>


<iframe src="test.html"></iframe>


test.html
----------

<script>

 function test()
 {
            parent.document.getElementById("test").value = document.getElementById("Andrew").value;
 }

</script>

<form action="andrew.htm" method="post" onclick="javascript: test();">
 <input type="text" name="Andrew" value="Test">
      <input type="submit" name="Submit" value="Submit">
</form>
0
 
RejojohnyCommented:
If I am not mistaken .. for javascript .. the literals have to be in single quotes .. so try ...
opener.document.getElementById('lblTest').text = document.Form1.fileAtt1.value;
0
 
tim_chamberlainAuthor Commented:
OK, I'm going to recap on this.  I have 2 .aspx web forms. The parent form contains an <asp:button that opens a pop-up window (attachment.aspx) using the following code:

Dim s As String = "<script>window.open('attachment.aspx?section=discussion','Attach','left=20,top=20,width=500,height=350,scrollbars=1,toolbar=1,status=1,resizable=0,menubar=1');</script>"
Me.RegisterStartupScript("WO", s)

Attachment.aspx has 3 HTML file fields called Att1, 2 and 3.

What I want to do is update the .text value of 3 <asp:hyperlink controls on the parent page with values selected in the child form (Attachment.aspx) when I close the child form.  What I also want to avoid is clearing any values entered in other <asp: ... controls in the parent window when the child window is closed.

If this is not possible I can handle this using session variables but I suspect there must be a cleaner way to do this using Javascript.  The examples above don't update the values in the parent form (including opener.document.getElementById('lblTest').text = document.Form1.fileAtt1.value;).

BTW - Rejojohny - I take your point re. splitting the points on my previous question regarding passing parameters to a user control. I was just trying to play by the rules but should have split the points. Thanks for your input though.
0
 
ScotBelshawCommented:
you can pass a function through to the child widow.
eg. on the parent form have a function like
function SetAttValues(att1, att2, att3){
  document.getElementById["lblAtt1"].value = att1;
  document.getElementById["lblAtt2"].value = att2;
  document.getElementById["lblAtt3"].value = att3;
}

then pass the function in the window.open call in the dialogArguments
var oArgs = new Object();
oArgs.SetAttValues = SetAttValues;
window.open('attachment.aspx', oArgs,'left=20,top=20,width=500,height=340,scrollbars=0,toolbar=0,status=0,resizable=0');

then in the close function call it.
function CloseWindow()
{
  var oArgs = window.dialogArguments;
  if( oArgs && oArgs.SetAttValues){
    oArgs.SetAttValues(document.Form1.fileAtt1.value, document.Form1.fileAtt2.value, document.Form1.fileAtt3.value);
  }  
  self.opener.location=self.opener.location.href;
  self.close();
}

its a bit messy but it might work better
0
 
tim_chamberlainAuthor Commented:
Thanks for the solutions.  I have adapted some elements from both answers and combined this with session variables to acheive what I needed.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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