AsyncFileUplaod losing target frame
My page has an IFRAME tag with a src pointing to another page which has 4 ImageButtons and a ModalPopupExtender that opens up a DIV that contains an AsyncFileUpload (AF开发者_运维知识库U) for loading pictures.
Whenever the user click an ImageButton the ModalPopupExtender opens up the DIV with the AFU control, the user select the picture and then the Imagebutton get the ImageURL of the selected image.
The first time I select an image to upload evrything works fine, the image is saved and the ImageButton gets the correct ImageURL and control goes back to the calling page (the one with the IFRAME tag). The second time the user click an ImageButton to open the ModalPopupExtender for selcting and uploading a picture the page open a new browser window with the iframed document as the main document...
I searched the web for a solution and found out that the AFU changes the document.forms[0].target so in my uploadComplete event I try to restore the document.forms[0].target to the correct target (the IFRAME id) but it still opens up in a new browser window with the iframed document as the main document.
Anyone can help with this ?
There is a known issue with the design of the ASP.NET AJAX AsyncFileUpload control: AsyncFileUpload changes browser location when used in IFRAME page. However, I am unable to reproduce this issue with v3.5.50731.0 of the toolkit and the sample code below.
Since your problem is occurring when the ImageButton is clicked, you should add an OnClientClick handler that resets the form target there - and it should probably be reset to ''
(empty string), since the ImageButton is already inside the IFRAME.
Here is the minimum sample, which I can't break with AjaxControlToolkit v3.5.50731.0:
<%@ Page Language="C#" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolKit" %>
<html><body>
<script runat="server">
int Id = Convert.ToInt32(HttpContext.Current.Request["Id"]);
</script>
<form runat="server">
<ajaxToolKit:ToolkitScriptManager runat="server" />
<h1>IFRAME <%= Id %></h1>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<ol><li><ajaxToolKit:AsyncFileUpload runat="server" /></li>
<li><asp:Button runat="server" Text="After the file is uploaded, click this button" /></li></ol>
</ContentTemplate>
</asp:UpdatePanel>
</form>
<% if (++Id % 3 != 0)
{ %><iframe src="?id=<%= Id %>" width="90%" name="iframe<%= Id %>" height="400px"
style="float: right" />
<% } %>
</body></html>
精彩评论