Jun 29, 2011, 10:13 PM
[CLOSED] Correct DirectResponse from an ashx handler
Hi,
I'm sure this has been answered before so apologies if so, but I searched quite a bit and didn't find it.
Consider the following:
ASPX:
Thanks!
I'm sure this has been answered before so apologies if so, but I searched quite a bit and didn't find it.
Consider the following:
ASPX:
<%@ Page Language="C#" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DirectEvent Request tests</title>
<script type="text/javascript">
function doRequest(simulation) {
Ext.net.DirectEvent.request({
url : 'DirectRequestTest.ashx',
cleanRequest: true,
extraParams : { success : simulation },
eventMask : { showMask:true },
success : function(result) { console.log('success', result); },
failure : function() { console.log('failure', arguments); }
});
}
</script>
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<form id="HtmlForm" runat="server">
<div>
<ext:Button ID="Request1" Text="Request a Success" runat="server">
<Listeners>
<Click Handler="doRequest(true);" />
</Listeners>
</ext:Button>
<ext:Button ID="Request2" Text="Request a Failure" runat="server">
<Listeners>
<Click Handler="doRequest(false);" />
</Listeners>
</ext:Button>
</div>
</form>
</body>
</html>
ASHX:using System.Web;
namespace Ext.Net.Tests.Events
{
public class DirectRequestTest : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
var response = new DirectResponse
{
Success = context.Request["success"] == "true"
};
if (response.Success)
{
response.Result = "some result";
var parameters = new ParameterCollection
{
new Parameter("test", "value")
};
response.ExtraParamsResponse = parameters.ToJson();
}
else
{
response.ErrorMessage = "Request failed";
}
response.Return();
}
public bool IsReusable
{
get { return false; }
}
}
}
Questions:- What am I doing wrong here (the success handler doesn't seem to fire though I can see the response in the http traffic)?
- When the failure request is simulated how do I prevent the default request failure window appearing (I found some examples of using Ext.net.Direct.Request() but while they had a success handler, they didn't have failure handlers. Should I be doing it another way?)
- Should I even bother using an ashx for this? Should I use a WebService (asmx) instead like this: https://examples1.ext.net/#/Events/D...ds/WebService/ ? [I am in a scenario where I can't assume a Page so can't use the nice [DirectMethod] approach which I'd normally have done here.] Is there any performance difference?
Thanks!
Last edited by Daniil; Jun 30, 2011 at 9:37 AM.
Reason: [CLOSED]