Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass parameter from child to parent window?

Status
Not open for further replies.

okayokayjustme

IS-IT--Management
Joined
Apr 5, 2007
Messages
73
Location
US
I'm triyng to pass a bunch of parameters from the popup child window to its parent window. However, I'm stock on the first part...that is getting the value from the ASP.NET Lable control. I've tried an alert like this:

Code:
alert("Document lable 1: " + document.getElementById('lable1').value)

And I got: Document lable 1: undefined

Any idea why?
 
Is lable1 (label1)? an id of an element in the same window that you type the alert in? Can you post some relevant code please?

[monkey][snake] <.
 
Thank you for the response. This is the lable control:

<asp:Label ID="lable1" runat="server" Font-Bold="True" ForeColor="MidnightBlue"></asp:Label><br />

And on the btnClose button, I have this:

<asp:Button ID="btnClose" runat="server" Text="Close" OnClientClick="sendInfo()" />

So in the javascript sendInfo function I put an alert box like this:

alert("Document lable 1: " + document.getElementById('lable1').value)

Now, this is just the first part and I already encounter problem.
 
I know nothing about asp.net, can you post what your source code looks like within a browser? View source and copy, thank you.

[monkey][snake] <.
 
<html xmlns=" >
<head><title>
Photo Attachment
</title>
<script language="javascript" type="text/javascript">
function sendInfo()
{
alert("Document lable 1: " + document.getElementById('lblAttach1').value)
}
</script>

/head>
<body>
<form name="frmAttachFile" method="post" action="fileAttach.aspx" id="frmAttachFile" enctype="multipart/form-data">
<div>

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTY3NTU4OTgwMw9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YWRksP5B0I5WHQyCJ7MNWGkQ1hbmDj4=" />
</div>

<table border="0" cellpadding="0" cellspacing="0" style="width: 325px">
<tr>
<td colspan="3" style="height: 14px">
Attach your photos:</td>
</tr>
<tr>
<td colspan="2">

<input type="file" name="fulAttach1" id="fulAttach1" /></td>
<td style="width: 100px">
Attachment 1</td>
</tr>

<tr>
<td colspan="2">
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<span id="lable1" style="color:MidnightBlue;font-weight:bold;"></span>
<td style="width: 100px" valign="top">
Files uploaded</td>
</tr>
<tr>
<td style="width: 51px">
<input type="submit" name="btnSubmit" value="Submit" id="btnSubmit" /></td>

<td style="width: 108px;">
<input type="submit" name="btnClose" value="Close" onclick="sendInfo();" id="btnClose" /></td>
<td style="width: 100px">
</td>
</tr>
</table>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLC79euDQLCi9reAwKT+PmaCEiqHsYNCAgll8DVE+GvgNK9MFiv" />

</div></form>
</body>
</html>
 
This line:

alert("Document lable 1: " + document.getElementById
('lblAttach1').value)

Should be this:

alert("Document lable 1: " + document.getElementById('lable1').value)

 
The only item with id="lable1" in your code is a <span>

Code:
<span id="lable1" style="color:MidnightBlue;font-weight:bold;"></span>

There is no value for that span. You can alert the innerHTML of the span:
Code:
alert("Document lable 1: " + document.getElementById('lable1').innerHTML)

I do remember somewhere seeing that asp:labels get transformed into <span>. As is though, you have no value set on that span, really a <span> shouldn't have a value assigned to it.


[monkey][snake] <.
 
Okay, many thanks for your help. I finally got the value of the lable inside of the span tag. However, when I try to send the backup from the popup child window back to the parent window, it's not working. Here's the view source code.

<html xmlns=" >
<head><title>
Photo Attachment
</title>
<script language="javascript" type="text/javascript">
function sendInfo()
{
var lblFileOne = document.getElementById('lblAttach1').innerHTML;
if(window.opener && !window.opener.closed)
{
alert("Document lable 1: " + document.getElementById('lable1').innerHTML)
window.opener.document.getElementById('lblFile1').innerHTML = lblFileOne;
window.close();
}
}
</script>
</head>
<body>
<form name="frmAttachFile" method="post" action="fileAttach.aspx" id="frmAttachFile" enctype="multipart/form-data">
<div>

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTY3NTU4OTgwMw9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YRYEAgcPDxYCHgRUZXh0BQ9maXJlZmlnaHRlci5qcGdkZAINDw8WAh4HRW5hYmxlZGhkZGQ/W9JkFAnYalxyBFYXuL9lvtZIpw==" />
</div>

<table border="0" cellpadding="0" cellspacing="0" style="width: 325px">
<tr>
<td colspan="3" style="height: 14px">
Attach your photos:</td>
</tr>
<tr>
<td colspan="2">

<input type="file" name="fulAttach1" id="fulAttach1" /></td>
<td style="width: 100px">
Attachment 1</td>
</tr>
<tr>
<td colspan="2">
<input type="file" name="fulAttach2" id="fulAttach2" /></td>
<td style="width: 100px">

Attachment 2</td>
</tr>
<tr>
<td colspan="2">
<input type="file" name="fulAttach3" id="fulAttach3" /></td>
<td style="width: 100px">
Attachment 3</td>
</tr>

<tr>
<td colspan="2">
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<span id="lable1" style="color:MidnightBlue;font-weight:bold;">firefighter.jpg</span>
</td>
<td style="width: 100px" valign="top">
Files uploaded</td>
</tr>
<tr>
<td style="width: 51px">
<input type="submit" name="btnSubmit" value="Submit" id="btnSubmit" disabled="disabled" /></td>

<td style="width: 108px;">
<input type="submit" name="btnClose" value="Close" onclick="sendInfo();" id="btnClose" /></td>
<td style="width: 100px">
</td>
</tr>
</table>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLxuK7DBwLCi9reAwKT+PmaCOTrK7S3qna9pWd0YqKlIMFMHs8p" />

</div></form>
</body>
</html>

The alert does work but it does at window.opener line.
 
Sorry, wish there is a way to edit my post.

This line:

var lblFileOne = document.getElementById('lblAttach1').innerHTML;

should be:

var lblFileOne = document.getElementById('lable1').innerHTML;
 
Your prior post spans outside of the browser width. [greedo]

[monkey][snake] <.
 
By the way, how do I fix this window problem?
How do delete my post?

What I was saying is that sending the value
back to the parent window is not working.

This is the code:
if(window.opener && !window.opener.closed)
{
alert("Document lable 1: " + document.getElementById('lable1').innerHTML)
window.opener.document.getElementById('lblFile1').innerHTML = lblFileOne;
window.close();
}

The alert works but not the window.opern line.
 
I kinda think I know why I'm unable to send the
information back. My page was under a MasterPage
in a ContenPlaceHolder. I have to access this
ContentPlaceHolder to access the Lable. Not how I
would that yet.
 
About the long width post: that problem is TT's problem, I'd just red flag it if you need/want it removed.


Ok I got another question. Do you have an element in your main window (window.opener window) that has an id of lblFile1?

I just did a test on what you are trying to do and the way you are doing it. It should work, my test example works.

Just make sure that there is an element called lblFile1 that can contain HTML.

[monkey][snake] <.
 
Yes, there is an element called lblFile1 in the
window.opener window (parent window). However, as
I mentioned above, I use master page. So to access
the element lblFile1, I need to access the
ContentPlaceHolder first and then the element
lblFile1. The problem is, I don't know how to access
element that is under the conten place holder. Here is
what the view source look like for the lblFile1 element.

<span id="ctl00_ContentPlaceHolder1_lblFile1" style="color:MidnightBlue;font-weight:bold;"></span>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top