[CLOSED] When directMethod returns True, I wish that window is closed

Page 2 of 2 FirstFirst 12
  1. #11
    Hi Daniil!

    Of course... follow the sample code!

    <%@ Page Language="vb" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        
        Protected Sub AddWindow(sender As Object, evt As Ext.Net.DirectEventArgs)
            Dim wnd As Ext.Net.Window
            wnd = getWindow()
            Me.Form.Controls.Add(wnd)
            wnd.Render()
            wnd.Show()
        End Sub
        
        Protected Function getWindow(Optional url As String = "~/test27.aspx", Optional pTitle As String = "test", Optional iconUrl As String = "") As Ext.Net.Window
            Dim wnd As New Ext.Net.Window
            Dim loader As New Ext.Net.ComponentLoader
            Dim btn As Ext.Net.Button
            Dim successHandler As String
           
            loader.Url = url
            loader.Mode = Ext.Net.LoadMode.Frame
            loader.LoadMask.ShowMask = True
            loader.LoadMask.Msg = "Carregando..."
    
            wnd.ID = "window_" & (New System.Random).Next(Integer.MaxValue).ToString
            wnd.Title = pTitle
            If iconUrl <> "" Then
            Else
                wnd.Icon = Ext.Net.Icon.ApplicationForm
            End If
            wnd.AutoRender = False
            wnd.Collapsible = False
            wnd.Hidden = True
            wnd.AutoRender = False
            wnd.Maximizable = False
            wnd.Loader = loader
            wnd.CloseAction = CloseAction.Destroy
            wnd.Width = 500
            wnd.Height = 400
            
            btn = New Ext.Net.Button
            btn.ID = "btnOk"
            btn.Text = "Ok"
            btn.TextAlign = ButtonTextAlign.Center
            btn.Icon = Icon.Accept
    
            successHandler = String.Format("function (result) {{ if (result) {{ {0}.close(); }}}}", wnd.ClientID)
            btn.OnClientClick = String.Format("{0}.getBody().{1}({{ success : {2} }});", wnd.ClientID, "App.direct.Save", successHandler)
    
            'btn.OnClientClick = wnd.ClientID & ".getBody().Ext.net.DirectMethods.Save();"
            wnd.Buttons.Add(btn)
            
            btn = New Ext.Net.Button
            btn.ID = "btnCancel"
            btn.Text = "Cancel"
            btn.TextAlign=ButtonTextAlign.Center 
            btn.Icon = Icon.Cancel
            btn.OnClientClick = wnd.ClientID & ".close();"
            wnd.Buttons.Add(btn)
            
            Return wnd
    
        End Function
        
        <DirectMethod()>
        Public Sub ShowMessage()
            Dim mb As New Ext.Net.MessageBox
            mb.Alert("Parent alert!", "This messages is triggered in parent!").Show()
        End Sub
        
        <DirectMethod()>
        Public Sub ShowWindow()
            Dim wnd As Ext.Net.Window
            wnd = getWindow("~/test25.aspx")
            Me.Form.Controls.Add(wnd)
            wnd.Render()
            wnd.Show()
        End Sub
        
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager ID="resManagerSGCO" runat="server"/> 
        <form id="form1" runat="server">
        <div>
            <ext:Button runat="server" ID="btnCreateWindow" Text="Create and Show Window" OnDirectClick="addWindow" />
        </div>
        </form>
    </body>
    </html>
    <%@ Page Language="vb" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        
        <DirectMethod()>
        Public Function Save() As Boolean
            Response.Write("Save triggered!!!")
            Return True
        End Function
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager ID="resManagerSGCO" runat="server" /> 
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>
  2. #12
    Thanks. I was able to reproduce with IE. I tried with FireFox where it's not reproducible.

    A small delay (1 ms) solves the problem.

    Please replace:
    successHandler = String.Format("function (result) {{ if (result) {{ {0}.close(); }}}}", wnd.ClientID)
    with
    successHandler = String.Format("function (result) {{ if (result) {{ Ext.defer({0}.close, 1, {0}); }}}}", wnd.ClientID)
  3. #13
    Hi Daniil!

    Works fine! Thanks a lot!
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 10
    Last Post: Apr 25, 2013, 5:38 AM
  2. Replies: 6
    Last Post: Apr 02, 2012, 6:37 PM
  3. Replies: 3
    Last Post: Mar 19, 2012, 12:35 PM
  4. [CLOSED] Move a window to the left with constrainHeader = true
    By softmachine2011 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 01, 2011, 10:43 AM
  5. [CLOSED] Window toFront: true
    By CarWise in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 20, 2011, 8:56 AM

Posting Permissions