[CLOSED] Window with frame, closed event

  1. #1

    [CLOSED] Window with frame, closed event

    Hi, I would like to redirect to another page once server-side function are executed, but...

    My scenario is the following:

    1. Page with a Window and a Button
    2. Button's Click opens the Window and loads inside the window another page, as a frame
    3. The page inside the window has a save button, with a listener click handler able to call the window hide method
      parent.Ext.getCmp('myWindow').hide();
    4. The handler runs before my server-side click; once the windows is hidden the save button click does its job


    I would like to redirect the response to another page, but if I add to the save button's click listener
    parent.document.location.href = "newpage.aspx";
    it runs before to save, redirects and does not save.

    What do you suggest me to do in order to save and then redirect?

    I have also a custom "DataUpdated" event but it runs inside the frame; could I maybe run something using the ResourceManger?

    thanks a lot!
    Last edited by fabricio.murta; Jan 03, 2018 at 3:59 PM.
  2. #2
    Hello @bbros!

    You got to set that up using a callback. Something that only fires after the server returns the "success" result.

    There are several ways to implement callbacks. One of them is just adding X.AddScript() with the code you need to run after the direct method/event returns.

    The other is setting the Success= and Failure= codes to the direct event itself, like

    <ext:Button runat="server" Text="My Button">
        <DirectEvents>
            <Click OnEvent="MyDirectEvent" Success="Ext.toast('it was a success!')" />
        </DirectEvents>
    </ext:Button>
    There are other ways, for example, close the window from code behind (assuming it can only be closed from code behind) then binding the Close listener to do whatever you need besides closing it.

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thanks Fabricio, AddScipt solved my problems.
    I produced a sample that works as expected.

    it consists of two pages, the frame container and the frame content.

    MainWebForm.aspx

    <%@ Page Language="vb" AutoEventWireup="false" Inherits="System.Web.UI.Page" %>
    
    <!DOCTYPE html>
    <script runat="server">
    
        Dim WithEvents myWindow As Ext.Net.Window
        Dim lblOutput As Ext.Net.Label
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim rm As New ResourceManager
            body.Controls.Add(rm)
    
            'Window
            Dim loader = New ComponentLoader With {
                            .Url = "FrameWebForm.aspx",
                            .Mode = LoadMode.Frame,
                            .AutoLoad = False}
            loader.LoadMask.ShowMask = True
    
            myWindow = New Window With
                {
                    .ID = "myWindow",
                    .Title = "Click close button",
                    .Width = Unit.Pixel(600),
                    .Height = Unit.Pixel(250),
                    .Modal = True,
                    .AutoRender = False,
                    .Collapsible = True,
                    .Maximizable = True,
                    .Hidden = True,
                    .Loader = loader
                }
            body.Controls.Add(myWindow)
    
            'Button
            Dim btnWin As New Ext.Net.Button With {.ID = "WinButton", .Text = "Open the window", .Icon = Icon.ApplicationForm}
            AddHandler btnWin.DirectClick, AddressOf btnWin_Click
            body.Controls.Add(btnWin)
    
            'Label
            lblOutput = New Ext.Net.Label With {.ID = "OutputLabel", .Text = "Waiting for output."}
            body.Controls.Add(lblOutput)
    
        End Sub
    
        Private Sub btnWin_Click(sender As Object, e As DirectEventArgs)
            myWindow.Show()
            myWindow.LoadContent()
        End Sub
    
        <DirectMethod>
        Public Sub UpdateOutput()
            If Session("Output") IsNot Nothing Then
                lblOutput.Text = Session("Output")
            Else
                lblOutput.Text = "No output found :("
            End If
        End Sub
    
    
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    </head>
    <body id="body" runat="server">
    </body>
    </html>
    FrameWebForm.aspx

    <%@ Page Language="vb" AutoEventWireup="false" Inherits="System.Web.UI.Page" %>
    
    <!DOCTYPE html>
    <script runat="server">
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim rm As New ResourceManager
            body.Controls.Add(rm)
    
            'Button
            Dim btnClose As New Ext.Net.Button With {.ID = "CloseButton", .Text = "Click to close", .Icon = Icon.ApplicationFormDelete}
            'the following line causes the window to close prematurely
            'btnClose.Listeners.Click.Handler = "parent.App.direct.UpdateOutput();parent.Ext.getCmp('myWindow').hide();"
            AddHandler btnClose.DirectClick, AddressOf btnClose_Click
            body.Controls.Add(btnClose)
        End Sub
    
        Private Sub btnClose_Click(sender As Object, e As DirectEventArgs)
            Session("Output") = "Mission accomplished!"
            Ext.Net.X.AddScript("parent.App.direct.UpdateOutput();parent.Ext.getCmp('myWindow').hide();")
        End Sub
    
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body id="body" runat="server">
    </body>
    </html>
    I commented the line #13 in 2nd file and added the line #20; in this way I have been able to perform my tasks and close the window only when tasks are completed.

    Thanks again, you can mark it as closed.
  4. #4
    Hello @bbros!

    Awesome! Thanks for sharing the code that worked for you, and glad the tips helped you find the way to make it work the way you needed it!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Window not rendering frame for content
    By jbarbeau in forum 2.x Help
    Replies: 2
    Last Post: Sep 02, 2014, 6:21 PM
  2. reload desktop window frame
    By krishna in forum 1.x Help
    Replies: 0
    Last Post: Mar 01, 2012, 12:51 PM
  3. [CLOSED] How to change window frame color
    By SFritsche in forum 1.x Premium Help
    Replies: 2
    Last Post: Feb 24, 2010, 7:59 PM
  4. Anchor modal window to parent frame
    By stone216 in forum 1.x Help
    Replies: 3
    Last Post: Jan 27, 2010, 3:40 PM
  5. [CLOSED] Pass value of row to window with frame
    By CSG in forum 1.x Premium Help
    Replies: 1
    Last Post: May 26, 2009, 1:29 PM

Posting Permissions