Nov 09, 2011, 4:10 AM
[CLOSED] Error when uploading file to httphandler
This is related to my other thread about posting file to DirectMethod http://forums.ext.net/showthread.php...g-DirectMethod . I have now decided to upload file to httphandler instead. My problem is that I am not able to send a response back to the client from my httphandler. I am getting a javascript error when decoding the response. I have struggled with this for hours now...
FileUpload.aspx
FileUpload.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="FileUpload.aspx.vb" Inherits="ExtSandbox.FileUpload" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Ext.Net.ResourceManager.RegisterControlResources(Of Ext.Net.FileUploadField)()
Me.resourceMgr.RegisterIcon(Ext.Net.Icon.Add)
Me.resourceMgr.RegisterIcon(Ext.Net.Icon.PageWhiteAdd)
Me.resourceMgr.RegisterIcon(Ext.Net.Icon.Disk)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script type="text/javascript">
// Compressor
Ext.ux.UploadWindow = Ext.extend(Ext.Window, {
title: 'Upload File',
iconCls: 'icon-pagewhiteadd',
width: 450,
height: 110,
modal: true,
closeAction: 'close',
form: null,
border: false,
submitUrl: '/ExtSandbox/FileUploadHandler.ashx',
layout: 'fit',
initComponent: function () {
this.form = new Ext.form.FormPanel({
layout: 'form',
frame: true,
fileUpload: true,
url: this.submitUrl,
items: [{
xtype: 'fileuploadfield',
fieldLabel: 'File Upload',
msgTarget: 'side',
anchor: '0',
iconCls: 'icon-add',
buttonText: ''
}
]
});
Ext.apply(this, {
items: this.form,
buttons: [{
text: 'Upload File',
iconCls: 'icon-disk',
formBind: true,
handler: this.uploadFile,
scope: this
}, {
text: 'Cancel',
scope: this,
handler: this.onCancel
}]
});
Ext.ux.UploadWindow.superclass.initComponent.call(this);
},
uploadFile: function () {
this.form.getForm().submit({
});
},
onCancel: function () {
this.closeAction();
}
});
Ext.reg('uploadwindow', Ext.ux.UploadWindow);
function showWindow() {
var win = new Ext.ux.UploadWindow({});
win.show();
}
</script>
<form id="aspnetForm" runat="server">
<ext:ResourceManager runat="server" ID="resourceMgr" Theme="Slate" ScriptMode="Debug">
</ext:ResourceManager>
<ext:Button runat="server" ID="btnShow" Text="Upload File">
<Listeners>
<Click Fn="showWindow" />
</Listeners>
</ext:Button>
</form>
</body>
</html>
FileUploadHandler.ashxImports System.Web
Imports System.Web.Services
Public Class FileUploadHandler
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
'handle file here
'send back success response
context.Response.ContentType = "application/json"
context.Response.ContentEncoding = Encoding.UTF8
Dim returnData = New With {.success = True, .msg = "Successful"}
context.Response.Write(Ext.Net.JSON.Serialize(returnData))
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Last edited by Daniil; Nov 09, 2011 at 1:56 PM.
Reason: [CLOSED]