PDA

View Full Version : [CLOSED] Handle lost internet connection



blueworld
Sep 02, 2013, 9:23 AM
Hi

currently I am developing an application that needs to tell the user if the internet connection is lost.

All these actions are DirectMethods or store reloads.

Currently I am getting this standard ext.net window with the title "Request Failure"

Status Code:
Status Text:

Is there a way to set a default text for that window like "Try again later, please check your internet connection ..."

Regards

Daniil
Sep 02, 2013, 2:09 PM
Hi @blueworld,

I can suggest the following.

<ext:ResourceManager runat="server" ShowWarningOnAjaxFailure="false">
<Listeners>
<AjaxRequestException Handler="/* show your custom failure window */" />
</Listeners>
</ext:ResourceManager>

The default failure window is being shown by Ext.net.DirectEvent.showFailure.

blueworld
Jan 29, 2014, 3:28 PM
Hi Daniil,

I have a directmethod with failure handler. I would like to show an Alert with a different Text, but the failure window is showing at the same time.
Is there a way to disable the failure window for that event?
Or is it possible to change the Text of the failure window for that moment, and set it back to default in the failure handler?




App.direct.doSomething(var1,var2, {
failure: function (message)
{
// Show alert but NOT the request failure window
}
});

Daniil
Jan 29, 2014, 3:45 PM
Hmm. a failure window should not be shown if there is a failure handler.

Example

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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
[DirectMethod]
public void TestDirectMethod()
{
throw new Exception();
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Button
runat="server"
Text="Click me"
Handler="App.direct.TestDirectMethod({ failure: function() { console.log('failure'); }})" />
</form>
</body>
</html>



Or is it possible to change the Text of the failure window for that moment, and set it back to default in the failure handler?

Hmm, seems I don't understand the requirement. Please elaborate.

blueworld
Jan 29, 2014, 4:55 PM
Hi Daniil,

please see this simple Demo.
console.log is executed but the window is shown at the same time.
Please note that I have used a custom handler.





<%@ Page Language="VB" %>

<%@ Import Namespace="System.Collections.Generic" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title></title>
<script runat="server">

<DirectMethod()>
Public Sub MyEvent()

Dim emptyList As Generic.List(Of Integer)

Dim number As Integer = emptyList(1)

End Sub

</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server">

<Listeners>
<AjaxRequestException Handler="Ext.Msg.alert('Error', 'There was an error!')" />
</Listeners>

</ext:ResourceManager>

<ext:Button runat="server" Text="Click me">
<Listeners>
<Click Handler="App.direct.MyEvent({failure: function(){console.log('Failure');}})" />
</Listeners>
</ext:Button>
</form>
</body>
</html>

Vladimir
Jan 29, 2014, 6:43 PM
What window do you mean? Do you mean your alert window?
If yes then it is expected behaviour because it is your code shown the alert. We cannot block it

When Daniil said


Hmm. a failure window should not be shown if there is a failure handler.

then it meant Ext.Net error window
Standard Ext.Net error window is not shown in your case

blueworld
Jan 29, 2014, 7:14 PM
What window do you mean? Do you mean your alert window?
If yes then it is expected behaviour because it is your code shown the alert. We cannot block it

When Daniil said

then it meant Ext.Net error window
Standard Ext.Net error window is not shown in your case

Thank you Vladimir.
I have a "please check your internet connection" alert window, instead of the default request-failure window.

I have an event, that could throw an exception if a unique constraint has been violated.

Is there any way, to show a different message if that happens?

Can I change the AjaxRequestException-Handler by code? If yes, I could set a different Text before the event ('Name does already exist'), and after that event (sucess or failure), I could change it back to the old text('Please check your internet connection').

Daniil
Jan 30, 2014, 4:03 AM
So, you want to change the error message in a DirectMethod's failure handler, to get it appeared in the AjaxRequestException listener?

If so, it looks impossible, because the AjaxRequestException event fires before a DirectMethod's failure handler.

Could you, please, clarify why you don't want to do all the required things directly inside the AjaxRequestException listener?