BeforeHide Window DirectEvent

  1. #1

    BeforeHide Window DirectEvent

    Hi All,

    In my project, Edit window contain form. When user click close (X) button on right top window.
    If form not save the confirm message box will be alert.

    But in test case, Edit window hide before the confirm message box alert.

    Where I did something wrong? Could you please advice.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
    protected void BeforeHide_Event(object sender, DirectEventArgs e) 
    {  
        // Check something on Database after that alert MessageBox
        
        MessageBoxConfig config = new MessageBoxConfig();
        config.Title = "QUESTION";
        config.Message = "Record not save yet! Do you want to back to form for save?";
        config.Closable = false;
        config.Icon = MessageBox.Icon.QUESTION;
        config.Buttons = MessageBox.Button.YESNO;
        config.MessageBoxButtonsConfig = new MessageBoxButtonsConfig
        {
            Yes = new MessageBoxButtonConfig { 
                Handler = "Ext.net.DirectMethods.DoYes()", 
                Text = "Yes" 
            },
            No = new MessageBoxButtonConfig { 
                Handler = "Ext.net.DirectMethods.DoNo()", 
                Text = "No"                         
            }
        };
        ExtNet.Msg.Show(config);
    }
    
    [DirectMethod]
    public void DoYes()
    {
        // Back to Form for Save Record
        Notification.Show(new NotificationConfig { Title = "Title", Icon = Icon.Information, Html = "yes" });
    }
    
    [DirectMethod]
    public void DoNo()
    {
        // Hide Window
        Notification.Show(new NotificationConfig { Title = "Title", Icon = Icon.Information, Html = "no" });
    }
    </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>Test Window Before Hide</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
        
            <ext:Button runat="server" Text="Show Window" Icon="Application">
                <Listeners>
                    <Click Handler="#{Window1}.show();" />
                </Listeners>
            </ext:Button>
            
            <ext:Window 
                ID="Window1" 
                runat="server" 
                Title="Record Form"  
                Icon="Application"
                Height="300" 
                Width="400"
                Padding="5" 
                Modal="true">
                <Items>
                    <ext:FormPanel ID="FormPanel1" runat="server" Padding="5" ButtonAlign="Right">
                        <Items>
                            <ext:TextField ID="CompanyField" runat="server" FieldLabel="Company" />
                            <ext:TextField ID="PriceField" runat="server" FieldLabel="Price"  />
                            <ext:TextField ID="ChangeField" runat="server" FieldLabel="Change"  />
                        </Items>
                        <Buttons>
                            <ext:Button ID="ButtonSave" runat="server" Text="Save" />
                            <ext:Button ID="ButtonCancel" runat="server" Text="Cancel" />                           
                        </Buttons>
                    </ext:FormPanel>
                </Items>
    	        <DirectEvents>
    	            <BeforeHide OnEvent="BeforeHide_Event" />
    	        </DirectEvents> 
            </ext:Window>
        </form>
    </body>
    </html>
  2. #2
    Hello!

    Look at the following sample:

    <%--<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test_editor_combo.aspx.cs" Inherits="testextnet.test_editor_combo" %>--%>
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
    
    [DirectMethod(ShowMask = true)]
    public void BeforeHide() 
    {  
        // Check something on Database after that alert MessageBox
         
        MessageBoxConfig config = new MessageBoxConfig();
        config.Title = "QUESTION";
        config.Message = "Record not save yet! Do you want to back to form for save?";
        config.Closable = false;
        config.Icon = MessageBox.Icon.QUESTION;
        config.Buttons = MessageBox.Button.YESNO;
        config.MessageBoxButtonsConfig = new MessageBoxButtonsConfig
        {
            Yes = new MessageBoxButtonConfig { 
                Handler = "Ext.net.DirectMethods.DoYes()", 
                Text = "Yes" 
            },
            No = new MessageBoxButtonConfig { 
                Handler = "Ext.net.DirectMethods.DoNo(); #{Window1}.hide();", 
                Text = "No"                         
            }
        };
        ExtNet.Msg.Show(config);
    }
     
    [DirectMethod]
    public void DoYes()
    {
        // Back to Form for Save Record
        Notification.Show(new NotificationConfig { Title = "Title", Icon = Icon.Information, Html = "yes" });
    }
     
    [DirectMethod]
    public void DoNo()
    {
        // Hide Window
        Notification.Show(new NotificationConfig { Title = "Title", Icon = Icon.Information, Html = "no" });
    }
    </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>Test Window Before Hide</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
             
         
            <ext:Button runat="server" Text="Show Window" Icon="Application">
                <Listeners>
                    <Click Handler="#{Window1}.show();" />
                </Listeners>
            </ext:Button>
             
            <ext:Window
                ID="Window1"
                runat="server"
                Title="Record Form" 
                Icon="Application"
                Height="300"
                Width="400"
                Padding="5"
                Modal="true">
                <Items>
                    <ext:FormPanel ID="FormPanel1" runat="server" Padding="5" ButtonAlign="Right">
                        <Items>
                            <ext:TextField ID="CompanyField" runat="server" FieldLabel="Company" />
                            <ext:TextField ID="PriceField" runat="server" FieldLabel="Price"  />
                            <ext:TextField ID="ChangeField" runat="server" FieldLabel="Change"  />
                        </Items>
                        <Buttons>
                            <ext:Button ID="ButtonSave" runat="server" Text="Save" />
                            <ext:Button ID="ButtonCancel" runat="server" Text="Cancel" />                           
                        </Buttons>
                    </ext:FormPanel>
                </Items>
                <Listeners>
                    <BeforeHide Handler="
                        if (!this.notCheckSave) {
                            Ext.net.DirectMethods.BeforeHide({ success: function() { 
                                #{Window1}.notCheckSave = true; 
                            }, scope: this }); 
                            return false;
                        }"></BeforeHide>
                    <Hide Handler="this.notCheckSave = false;"></Hide>
                </Listeners>
            </ext:Window>
        </form>
    </body>
    </html>
  3. #3
    Great!!!

    You save my day. :)

Similar Threads

  1. Replies: 5
    Last Post: Jun 17, 2013, 2:33 PM
  2. Replies: 4
    Last Post: May 01, 2013, 1:01 PM
  3. [CLOSED] Help with window.open and directevent in safari
    By Pablo_Azevedo in forum 1.x Premium Help
    Replies: 8
    Last Post: Aug 10, 2011, 9:16 PM
  4. [CLOSED] Updating window size during DirectEvent
    By jmcantrell in forum 1.x Premium Help
    Replies: 4
    Last Post: Sep 13, 2010, 10:42 PM
  5. [CLOSED] Open a browser window from a DirectEvent
    By jmcantrell in forum 1.x Premium Help
    Replies: 1
    Last Post: Sep 07, 2010, 7:55 PM

Tags for this Thread

Posting Permissions