PDA

View Full Version : [CLOSED] submitting file to ashx in IE browser



odyssey
Jul 10, 2014, 12:28 PM
IE popups a dialog to save a json file in the example bellow.Which is not true in other browsers


<ext:FormPanel runat="server" ID="frmUploadImage" Layout="HBoxLayout" AnchorHorizontal="100%" BodyStyle="background-color:transparent" Border="false" Url="~/handlers/project_images.ashx/saveNewImages">
<Items>
<ext:FileUploadField runat="server" ID="fufImageUpload" AllowBlank="false" ValidateBlank="true" Text="" Name="fileUpload" Width="400" LabelWidth="125">
</ext:FileUploadField>
<ext:Button runat="server" ID="btnSaveImage" Text="Upload" Icon="DiskUpload" Flat="false">
<Listeners>
<Click Handler="Ext.getCmp('frmUploadImage').getForm().submit() ">
</Click>
</Listeners>
</ext:Button>
</ext:FormPanel>


the handler returns


msgBox.Show(new MessageBoxConfig()
{
Icon = MessageBox.Icon.ERROR,
Message = "Images size exceeds maximum allowed (1MB)!!!",
Title = "Project Images",
Fn = new JFunction { Handler = "mssoc.templates.fn.setFileUploadCaption();Ext.getS tore('storeImageManagement').load();" }
}
return new DirectResponse(msgBox.ToScript());

In non IE browsers the messagebox box displays just fine but in IE it popups a dialog to download the json file.The content type is set correctly "application/json";

Daniil
Jul 10, 2014, 1:17 PM
Hi @odyssey,

I think the IsUpload="true" setting might be required for a DirectResponse.

odyssey
Jul 11, 2014, 7:37 AM
Well then the script is not being executed at all .It wrap ups the script in textarea tag

Daniil
Jul 11, 2014, 4:12 PM
It appears that it is a known IE issue when it tries to "download" an "application/json" response.
http://stackoverflow.com/questions/13943439/json-response-download-in-ie710

Yes, IsUpload="true" wraps a response in a <textarea>. It is supposed to do that. And it helps to get it working in my test case.

Page

<%@ Page Language="C#" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:FormPanel
ID="FormPanel1"
runat="server"
Url="TestHandler.ashx">
<Items>
<ext:FileUploadField runat="server" Width="400" />
<ext:Button runat="server" Text="Upload" Handler="App.FormPanel1.getForm().submit();" />
</Items>
</ext:FormPanel>
</form>
</body>
</html>


ASHX

using System.Web;
using Ext.Net;

namespace Work2
{
public class TestHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
new DirectResponse
{
Script = X.Msg.Alert("Title", "Message").ToScript(),
IsUpload = true
}.Return();
}

public bool IsReusable
{
get
{
return false;
}
}
}
}

odyssey
Jul 14, 2014, 9:46 AM
You are right. Two things.
First the requested method return type should be changed from DirectResponse to void ,and new DirectResponse shout include Return()
like this

new DirectResponse
{
Script = msgBox.ToScript(),
IsUpload = true
}.Return();