Catch the OnUnload Ajaxevent

  1. #1

    Catch the OnUnload Ajaxevent

    Hi there,

    I would like to remove some session parameters when I leave a page, in order to free the sessionstate.

    I have tried to do this in the Page_Unload event but it is fired when I go into the page, because is on the server side,

    Well I tried to do in a Ajaxevent with javascript like:

    <html> 
    <head> 
        <title>Abre al salir</title> 
        <script> 
        function abreventana(){ 
           window.open("http://www.google.es","venta","") 
        } 
        </script> 
    </head>
    <body &#111;nunload="abreventana()"> 
    ...
    The problem is that my page is like this:

    
    
    
    <%@ Page Language="C#" MasterPageFile="~/Masters/MasterPage.master" AutoEventWireup="true" CodeFile="ModificarPeticionFrm.aspx.cs" Inherits="Conexion_Peticiones_ModificarPeticionFrm" Title="Untitled Page" %>
    
    
    <%@ Register Src="~/Conexion/Controles/UcModificarPeticion.ascx" TagName="CrearPeticion" TagPrefix="uc" %>
    
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    
     
    
    
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
    
    
    <ext:BorderLayout ID="BorderLayout1" runat="server"> 
    
    
    <Center>
    
    
    <ext:Panel ID="Panel1" runat="server">
    
    
    <Body>
    
    
    <ext:AnchorLayout ID="AnchorLayout1" runat="server">
    
    
    <ext:Anchor>
    
    
    <ext:Panel ID="Panel3" runat="server" AutoScroll="true">
    
    
    <Body>
    
    
    <uc:CrearPeticion ID="crearPeticion" runat="server" />
    
    
    </Body> 
    
    
    </ext:Panel>
    
    
    </ext:Anchor> 
    
    
    </ext:AnchorLayout>
    
    
    </Body> 
    
    
    </ext:Panel> 
    
    
    </Center>
    
    
    </ext:BorderLayout>
    
    
    </asp:Content>
    And I don't have any idea where could I place the event..

    Any idea??

    Thanx!
  2. #2

    RE: Catch the OnUnload Ajaxevent

    Hi!

    Try to use pure ExtJs solution like in CometDesktop:
    /* Start listen */
      if ( Ext.isIE )
    
                
    Ext.EventManager.on(window,'beforeunload',this.eventUnloadIE, this);
    
            else 
    
                Ext.EventManager.on(window,'beforeunload',this.eventUnload, 
    this, true);
    
    
    /* handles if IE */
    
           eventUnloadIE: function(e) {
    
            var _this = this;
    
    
    
            function unload() {
    
                return _this.eventUnload(e);
    
            }
    
                    
    
            function stop() {
    
                &#100;ocument.detachEvent('onstop', stop);
    
                return unload(e);
    
            }
    
            
    
            switch ( &#100;ocument.readyState ) {
    
                case 'interactive':
    
                    &#100;ocument.attachEvent('onstop', stop);
    
                    window.setTimeout(function() {
    
                        &#100;ocument.detachEvent('onstop', stop);
    
                    }, 0);
    
                    break;
    
                    
    
                default:
    
                    return unload(e);
    
                    break;
    
            }
    
        },
    
        
    
    
    /* handles if not IE */
    
        eventUnload: function(e) {
    
            
    /* Here you can make what you want */
    
    /*var x = Ext.lib.Ajax.createXhrObject();
    
            x.conn.open('POST','unload.pl',false); // sync request
    
            
    
            var originalTitle = &#100;ocument.title;
    
            &#100;ocument.title = 'Please wait...';
    
    
    
            if (this.fireEvent('beforeunload', this, x) === false) {
    
                if ( e ) e.stopEvent();
    
                &#100;ocument.title = originalTitle;
    
                return;
    
            }
    
            
    
            x.conn.setRequestHeader( 'X-SessionTime', 
    this.startTime.dateFormat('c/U') + '~' + ( new Date ).dateFormat('c/U') 
    );
    
            x.conn.setRequestHeader( 'X-LoadTime', this.loadTime );
    
            x.conn.onreadystatechange = Ext.emptyFn;
    
            x.conn.send( 'v'+this.config.version  );
    
            &#100;ocument.title = originalTitle;*/
    
        }

Similar Threads

  1. [CLOSED] Catch 404 Error
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 13, 2012, 9:06 AM
  2. [1.0] how to catch keys pressed on codebehind
    By marcelodecon in forum 1.x Help
    Replies: 1
    Last Post: Aug 11, 2010, 9:45 PM
  3. Catch Exceptions
    By Dominik in forum 1.x Help
    Replies: 1
    Last Post: Jun 10, 2010, 7:39 AM
  4. catch HttpRequestValidationException
    By [WP]joju in forum 1.x Help
    Replies: 4
    Last Post: Dec 21, 2009, 9:51 AM
  5. [CLOSED] Catch any failure
    By acrossdev in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 23, 2009, 7:27 AM

Posting Permissions