Hi,
Please provide the best practice and preferrably a code sample to handle exceptions thrown in DirectEvent code.
Thanks,
Vadym
Printable View
Hi,
Please provide the best practice and preferrably a code sample to handle exceptions thrown in DirectEvent code.
Thanks,
Vadym
Hi,
DirectEvent/DirectMethod has Failure handler.
A DirectEventArgs instance has the Success and ErrorMessage properties.
Here is the example how to handle exceptions in DirectMethods.
https://examples1.ext.net/#/Events/D...ds/Exceptions/
There is the AjaxRequestException handler in ResourceManager to handle exceptions globally. Here is some example:
http://forums.ext.net/showthread.php?9261
Store has the Exception event.
Hope this helps.
Thanks Daniil,
Do you have any actual code example dealing with Direct Event exception handling? After throwing an exception, the flow of execution simply continues in the Event code. I want it to stop, go to the error handler and present an error message popup on the client side.
Thanks,
Vadym
There won't be any changes compared to the example with DirectMethods:
https://examples1.ext.net/#/Events/D...ds/Exceptions/
apart from using
instead ofQuote:
A DirectEventArgs instance has the Success and ErrorMessage properties.
and using the DirectEvent's Failure handler instead of the DirectMethod's "failure" one.Code:Ext.Net.ResourceManager.AjaxSuccess = false;
Ext.Net.ResourceManager.AjaxErrorMessage = e.Message;
Here's my code:
On Failure, I'd like to present a popup with an error message. I need to get the value of the failure parameter in the Failure handler. Please help me with the correct syntax.Code:<ext:Button ID="ButtonSave" runat="server" Text="Save" Icon="Disk" Width="80">
<DirectEvents>
<Click Before="if (!#{Form1}.getForm().isValid()) {
Ext.net.Notification.show({
iconCls: 'icon-exclamation',
html: 'Form is invalid!',
title: 'Error'
});
return false;
}" OnEvent="ButtonSave_Click" Failure="Ext.Msg.alert(failure);"
Success="
var form=#{Form1};
if (form.record == null) {
return false;
}
form.getForm().updateRecord(form.record);">
<EventMask ShowMask="true" />
</Click>
</DirectEvents>
</ext:Button>
Thanks,
Vadym
Here is the full example.Code:result.errorMessage
Example
Btw, there is a simple way to quickly investigate arguments of any handler.Code:<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void TestDirectEventHandler(object sender, DirectEventArgs e)
{
e.Success = false;
e.ErrorMessage = "I'm the Error!";
}
</script>
<!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>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Button runat="server" Text="Click me">
<DirectEvents>
<Click OnEvent="TestDirectEventHandler" Failure="alert(result.errorMessage);" />
</DirectEvents>
</ext:Button>
</form>
</body>
</html>
Code:<DirectEvents>
<Click OnEvent="TestDirectEventHandler" Failure="debugger;" />
</DirectEvents>
That's exactly what I was after! Very much appreciated. This debugger quirk may come pretty handy, too.
I believe, global exception handling is done differently as I've seen traces of this discussion on the forum.
Thanks,
Vadym