PDA

View Full Version : [CLOSED] problems with WindowUnload



JCarlosF
May 06, 2013, 8:21 PM
I have a page with the name Principal.aspx, in which I have the following code:



<ext:resourcemanager id="ResourceManager1" runat="server" theme="Gray" >
<Listeners>
<WindowUnload Handler ="App.direct.Cerrando();" />
</Listeners>
</ext:resourcemanager>






<DirectMethod()> _
Public Sub Cerrando()
Try
Dim valAnio, valMes, valFuentes As String
valAnio = Session("AnioAud").ToString.Trim
Dim oRegBlq = From w In MyBase.dbAudex.WRegBlq Where w.EmpCia = MyBase.EmpCia And w.Anio = valAnio Select w
If oRegBlq.Count > 0 Then
For Each reg In oRegBlq
' fechaH = reg.Hora.Value.AddMinutes(10)
'If fechaH < fechaHora Then
MyBase.dbAudex.WRegBlq.DeleteObject(reg)
'End If
Next
MyBase.dbAudex.SaveChanges()
End If

valAnio = Nothing
valMes = Nothing
valFuentes = Nothing

Catch ex As Exception

End Try

'cerramos la sesion
FormsAuthentication.SignOut()
Session.Abandon()
End Sub

also I have a button to exit the application, with the next event on click.



Protected Sub btnSalir_Click(sender As Object, e As DirectEventArgs)
FormsAuthentication.SignOut()
Session.Abandon()
Response.Redirect("Default.aspx", True)
End Sub



but when I do that, I sent the following screen:

6165

why?

thanks!

Baidaly
May 06, 2013, 11:57 PM
Hello!

It's correct behavior because when you click on the button you force browser to change the location and in the same moment you send request which cannot be finished because browser is loading another page.

I can suggest another solution in this case:


<%@ Page Language="VB" %>

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

<!DOCTYPE html>

<html>
<head runat="server">
<script runat="server">
<DirectMethod()> _
Public Sub Cerrando()
Try
Dim valAnio, valMes, valFuentes As String
valAnio = Session("AnioAud").ToString.Trim

valAnio = Nothing
valMes = Nothing
valFuentes = Nothing

Catch ex As Exception

End Try

'cerramos la sesion
FormsAuthentication.SignOut()
Session.Abandon()
End Sub

Protected Sub btnSalir_Click(sender As Object, e As DirectEventArgs)
FormsAuthentication.SignOut()
Session.Abandon()
ResourceManager1.AddScript("App.direct.Cerrando({" &
"success: function (result) {" &
"window.location = '/Default.aspx';" &
"}" &
"});")
End Sub
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" ID="ResourceManager1">
</ext:ResourceManager>

<ext:Button runat="server" Text="Exit" Icon="ArrowOut">
<DirectEvents>
<Click OnEvent="btnSalir_Click"></Click>
</DirectEvents>
</ext:Button>
</form>
</body>
</html>

JCarlosF
May 08, 2013, 3:07 PM
Hello!

It's correct behavior because when you click on the button you force browser to change the location and in the same moment you send request which cannot be finished because browser is loading another page.

I can suggest another solution in this case:


<%@ Page Language="VB" %>

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

<!DOCTYPE html>

<html>
<head runat="server">
<script runat="server">
<DirectMethod()> _
Public Sub Cerrando()
Try
Dim valAnio, valMes, valFuentes As String
valAnio = Session("AnioAud").ToString.Trim

valAnio = Nothing
valMes = Nothing
valFuentes = Nothing

Catch ex As Exception

End Try

'cerramos la sesion
FormsAuthentication.SignOut()
Session.Abandon()
End Sub

Protected Sub btnSalir_Click(sender As Object, e As DirectEventArgs)
FormsAuthentication.SignOut()
Session.Abandon()
ResourceManager1.AddScript("App.direct.Cerrando({" &
"success: function (result) {" &
"window.location = '/Default.aspx';" &
"}" &
"});")
End Sub
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" ID="ResourceManager1">
</ext:ResourceManager>

<ext:Button runat="server" Text="Exit" Icon="ArrowOut">
<DirectEvents>
<Click OnEvent="btnSalir_Click"></Click>
</DirectEvents>
</ext:Button>
</form>
</body>
</html>



This is excellent, and works well, but does not enter the event Cerrando (),
and I need to come in, because that way, I close the session if the user closes the browser,
or how I prevent that?

Thanks!

Baidaly
May 08, 2013, 3:18 PM
This is excellent, and works well, but does not enter the event Cerrando (),
and I need to come in, because that way, I close the session if the user closes the browser,
or how I prevent that?

Thanks!

Couldn't reproduce. I put a breakpoint inside this method and it stopped. Did you use the same sample to test?

6183

JCarlosF
May 08, 2013, 3:59 PM
Couldn't reproduce. I put a breakpoint inside this method and it stopped. Did you use the same sample to test?

6183


yes, I already Use the same sample, and does not enter the Cerrando() event,

If you have any suggestions to close the session when you close the browser, with that solved, because I did that before with windowunload

thanks!

Baidaly
May 08, 2013, 9:19 PM
I'll ask my colleagues to test it too. But can you say which browser do you use?

JCarlosF
May 08, 2013, 9:43 PM
yes, I already Use the same sample, and does not enter the Cerrando() event,

If you have any suggestions to close the session when you close the browser, with that solved, because I did that before with windowunload

thanks!


I solved this by creating a variable-hidden-type,


<ext:Hidden ID="hClickSalir" runat="server" />

codebehind:


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Ext.Net.X.IsAjaxRequest Then
hClickSalir.Text = False
End If
End Sub

Protected Sub btnSalir_Click(sender As Object, e As DirectEventArgs)
hClickSalir.Text = True
FormsAuthentication.SignOut()
Session.Abandon()

ResourceManager1.AddScript("App.direct.Cerrando({" &
"success: function (result) {" &
"window.location = '/Default.aspx';" &
"}" &
"});")
End Sub





<ext:resourcemanager id="ResourceManager1" runat="server" >
<Listeners>
<WindowUnload Handler ="if (#{hClickSalir}.getValue() == 'False') {App.direct.Cerrando()};" />
</Listeners>
</ext:resourcemanager>


with this closes the session by closing the browser, and it gives no problems when I click on exit button

but still I have not managed to enter into the Cerrando() event,
but I do not it need much

thanks!

JCarlosF
May 08, 2013, 9:47 PM
I'll ask my colleagues to test it too. But can you say which browser do you use?

I already tried the browser Internet Explorer 10 and Chrome, and none entered the event Cerrando()

Vladimir
May 08, 2013, 9:52 PM
Please note that async ajax request in the unload event can be terminated by browser (because document is destroyed)
It is not Ext.Net issue
You can try sync ajax request (it is not goo solution imho) ot try beforeunload event (in this case response cannot be handled in any way)
You can find many discussions about using ajax request in unload and beforeunload events in the internet

JCarlosF
May 08, 2013, 10:12 PM
Please note that async ajax request in the unload event can be terminated by browser (because document is destroyed)
It is not Ext.Net issue
You can try sync ajax request (it is not goo solution imho) ot try beforeunload event (in this case response cannot be handled in any way)
You can find many discussions about using ajax request in unload and beforeunload events in the internet



Ok, I appreciate the suggestions, I will investigate on this issue, but for now, this is solved with the information provided, thanks!