AjaxFileUpload control doesn't work if it's placed on an initially invisible Panel control. Files can be selected on the client side, but if the user clicks the Upload button then the upload will not be finished and it remains in a failed state.
The following example demonstrates how can the problem be reproduced:
<script type=”text/javascript”>
function onClientUploadComplete(sender, e) {
}
</script>
<asp:Button ID="bt1" runat="server" Text="Show upload panel" OnClick="bt1_Click" />
<asp:Panel ID="p1" runat="server" Visible="false">
<asp:AjaxFileUpload ID="ajaxFileUpload" runat="server"
OnClientUploadComplete="onClientUploadComplete"
OnUploadComplete="ajaxFileUpload_OnUploadComplete"
MaximumNumberOfFiles="1" />
</asp:Panel>
------------- Code behind --------------
protected void bt1_Click(object sender, EventArgs e)
{
p1.Visible = true;
}
protected void ajaxFileUpload_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
{
}
The following script error will be experienced if the user tries to upload any file onto the server:
Sys.ArgumentException: Sys.ArgumentException: Cannot deserialize. The data does not correspond to valid JSON. Parameter name: data
The problem can be worked around by placing another AjaxFileUpload control inside an invisible HTML div tag on the same page attaching the same client and server side upload complete event handlers to both AjaxFileUpload control.
<div style="display:none">
<asp:AjaxFileUpload ID="ghostAjaxFileUpload" runat="server"
OnClientUploadComplete="onClientUploadComplete"
OnUploadComplete="ajaxFileUpload_OnUploadComplete"
/>
</div>
AjaxControlToolkit:
Runtime Version: v4.0.30319
Version: 4.1.60919.0
Target framework: .NET Framework 4.0
Comments: I absolutely cannot believe something this ridiculous actually solved the problem. I inherited a monstrous code base and fought with this problem for unimagined hours. Added the ghost control as you detailed and problem solved. Never would I have figured out this solution on my own. THANK YOU!!!
The following example demonstrates how can the problem be reproduced:
<script type=”text/javascript”>
function onClientUploadComplete(sender, e) {
}
</script>
<asp:Button ID="bt1" runat="server" Text="Show upload panel" OnClick="bt1_Click" />
<asp:Panel ID="p1" runat="server" Visible="false">
<asp:AjaxFileUpload ID="ajaxFileUpload" runat="server"
OnClientUploadComplete="onClientUploadComplete"
OnUploadComplete="ajaxFileUpload_OnUploadComplete"
MaximumNumberOfFiles="1" />
</asp:Panel>
------------- Code behind --------------
protected void bt1_Click(object sender, EventArgs e)
{
p1.Visible = true;
}
protected void ajaxFileUpload_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
{
}
The following script error will be experienced if the user tries to upload any file onto the server:
Sys.ArgumentException: Sys.ArgumentException: Cannot deserialize. The data does not correspond to valid JSON. Parameter name: data
The problem can be worked around by placing another AjaxFileUpload control inside an invisible HTML div tag on the same page attaching the same client and server side upload complete event handlers to both AjaxFileUpload control.
<div style="display:none">
<asp:AjaxFileUpload ID="ghostAjaxFileUpload" runat="server"
OnClientUploadComplete="onClientUploadComplete"
OnUploadComplete="ajaxFileUpload_OnUploadComplete"
/>
</div>
AjaxControlToolkit:
Runtime Version: v4.0.30319
Version: 4.1.60919.0
Target framework: .NET Framework 4.0
Comments: I absolutely cannot believe something this ridiculous actually solved the problem. I inherited a monstrous code base and fought with this problem for unimagined hours. Added the ghost control as you detailed and problem solved. Never would I have figured out this solution on my own. THANK YOU!!!