views:

397

answers:

1

I've got an ASP.NET 3.5 web app where I am trying to return a string from a child window to a parent window. It works in FF, Chrome, and Safari, but IE is a different story. In IE, it works the first time through but when reopening the child and passing another string, the parent page hangs in the middle of the PostBack.

For the parent window ascx, I have the following:

<script type="text/javascript">
    function openMediaManager() {
        // This is called to open the child window.
        window.open('/mediamanager.aspx', 'mediamanager', 'width=685, height=530');
    }

    function setImagePath(img) {
        // This is called by the child window to pass the string to the parent.
        <asp:Literal ID="NewImgPostBack" runat="server" />
    }
</script>

And a snippet from the code behind to generate the __doPostBack() call:

protected override void Render(HtmlTextWriter writer)
{
    // Not using the Button's OnClick because I have to use FindControl() to get the button.
    string postBack = Page.ClientScript
        .GetPostBackEventReference(MediaManagerButton, string.Empty)
            .Replace("''", "{0}");

    NewImgPostBack.Text = string.Format(postBack, "img");

    base.Render(writer);
}

In the child ascx, I am calling the the following function with a path to a file (example: "/image.png"):

<script type="text/javascript">
    function sendValueToParent(path) {
        // Called by the child to pass a string (path to an image) to the parent.
        window.opener.setImagePath(path);
        window.close();
    }
</script>

Any ideas why this would hang in IE only? I am using IE 7, but I have also read of the same problem in IE 6 (which most of the end users will have).

A reference to a similar problem: Why does Internet Explorer 7 hang bizarrely when child window scripts the parent window to submit?

EDIT

If I view source of the parent (child has already closed) while the page seems to hang in IE, I see the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head><title>title
</title><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><link id="ctl00_SiteStyle" rel="stylesheet" type="text/css" href="/App_Themes/20/css/a.css?v=3.0.0.1" />

    <script type="text/javascript" src="/javascript/_common.js"></script>

    <script type="text/javascript" src="/javascript/_calendar.js"></script>
</head>
<body>
    <form name="aspnetForm" method="post" action="/home.aspx" id="aspnetForm">
    <div>
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMTY1ODQ0NjQxD2QWAmYPZBYEAgEPZBYCAgMPFgIeBGhyZWYFJy9BcHBfVGhlbWVzL1NCMjAvY3NzL2FtbGkuY3NzP3Y9My4wLjAuMWQCAw9kFgoCAQ9kFgYCAQ8PFgQeBFRleHQFCURFViBMb2dpbh4HVmlzaWJsZWhkZAIDDw8WBh8BBQhIVFRQIEdFVB4LTmF2aWdhdGVVcmwFCi9ob21lLmFzcHgfAmdkZAIFDw8WBB8BBQZMb2cgSW4fAmhkZAIFD2QWBAIDD2QWAgIBD2QWCGYPDxYCHwJnZBYEZg8PFgYeCEltYWdlVXJsBR8vaW1hZ2VzL2Ntc2ljb25zL2VkaXRfc21hbGwucG5nHghDc3NDbGFzcwURQ01TRWRpdE1lbnVfSW1hZ2UeBF8hU0ICAhYCHgtvbm1vdXNlb3ZlcgUzZGlzcGxheU1lbnUoJ2N0bDAwX0NvbnRlbnRNYWluX2N0bDAxX2N0bDAwX2N0bDAxJyk7ZAIBDw8WBB8FBRRDTVNFZGl0TWVudV9NYWluTWVudR8GAgIWBB8HBRVkaXNwbGF5TWVudSh0aGlzLmlkKTseCm9ubW91c2VvdXQFEmhpZGVNZW51KHRoaXMuaWQpOxYOZg8PFgQfBQUaQ01TRWRpdE1lbnVfTWVudUl0ZW1CdXR0b24fBgICFgQfBwUXdGhpcy5vZmZzZXRQYXJlbnQubW89MTsfCAUXdGhpcy5vZmZzZXRQYXJlbnQubW89MDsWAmYPDxYEHwUFGUNNU0VkaXRNZW51X01lbnVJdGVtUGFuZWwfBgICFgQfBwUadGhpcy5jbGFzc05hbWU9J01JUEhvdmVyJzsfCAUSdGhpcy5jbGFzc05hbWU9Jyc7FgRmDw8WBh8EBSMvaW1hZ2VzL2Ntc2ljb25zL2VkaXRtb2RlX3NtYWxsLnBuZx8FB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z

(End)

Do you think this could be some ViewState issue? Sometimes when I leave the IE window open, after about 5 minutes, it seems to time out and loads a page with no styling.

A: 

its just a guess - but maybe try keeping a reference to the window in the opener:

var mediaMan;
function openMediaManager() {
    // This is called to open the child window.
    if (mediaMan)
      alert("already open!");
    else
       mediaMan = window.open('/mediamanager.aspx', '', 'width=685, height=530');
}

and then, instead of closing the window in the sendValueToParent, close it in the setImagePath

function setImagePath(path) {
   // do whatever
   if (mediaMan)
   {
     mediaMan.close();
     mediaMan = null;
   }
}

I often found that using a different approach works in ie - if i find a problem like this. Using this method you can also check if one mediamanger is already open (thus removing the need to name the window and allowing two instances of your webpage without one interfering with the other).

Niko
Good thought, but same result.
Aaron
do you know where exactly it hangs? try adding an alert before the close(); or isnt it event getting to setImagePath()?
Niko
It is getting to setImagePath() and also hits close(). It seems to hang up on the server side... ? I edited the question to give some more detail about the hang.
Aaron