[CLOSED] I wish get the parent ID in Code Behind

  1. #1

    [CLOSED] I wish get the parent ID in Code Behind

    Hi!

    Hi! I create a window in code behind (test23.aspx code) and I´m loading a aspx page (test24.aspx) within of window.
    I wish, in a codebehind procedure of test24.aspx, get the ID of window that contains the test24.aspx.

    Follow a little sample! In procedure ShowWindowParentID of test14.aspx, I wish get the window ID.

    Test23.aspx
    <!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 = "~/test24.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
    
            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
            'btn.OnClientClick = wnd.ClientID & ".getBody().Ext.net.DirectMethods.SaveRecord();"
            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
        
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager ID="resManagerSGCO" runat="server" Namespace="SuperaWeb.SGCO" /> 
        <form id="form1" runat="server">
        <div>
            <ext:Button runat="server" ID="btnCreateWindow" Text="Create and Show Window" OnDirectClick="addWindow" />
        </div>
        </form>
    </body>
    </html>
    Test24.aspx
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test24.aspx.vb" Inherits="WebApplication3.Test24" %>
    <%@ 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 ShowWindowParentID(sender As Object, evt As Ext.Net.DirectEventArgs)
            Dim mb As New Ext.Net.MessageBox
            mb.Alert("ParentID", "I wish show the parent window ID here!")
            mb.Show()
        End Sub
        
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="resManagerSGCO" runat="server" Namespace="SuperaWeb.SGCO" /> 
        <ext:Button runat="server" ID="btnGetParentWindowID" Text = "Show Parent Window ID" OnDirectClick="ShowWindowParentID" />
        </form>
    </body>
    </html>
    Last edited by Daniil; Mar 13, 2012 at 5:58 PM. Reason: [CLOSED]
  2. #2
    Hi,

    There is no way to get it on server side. But it's possible to get an id on client side and send it as a DirectEvent extra parameter.
  3. #3
    Is there any example I can follow?
  4. #4
    Well, via DirectEvent ExtraParams.
    <ext:Parameter Name="id" Value="parentAutoLoadControl.id" Mode="Raw" />
  5. #5
    Hi Daniil

    I'm sorry, but I'm doing something wrong!

    I insert the extraparam tag in directevent of button... but I get error when the page test24.aspx is loaded.

    Runtime Error in Microsoft JScript: 'parentAutoLoadControl' is not defined.

    Follow my changes in Test24.aspx... Test23.aspx is the same...
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test24.aspx.vb" Inherits="WebApplication3.Test24" %>
    <%@ 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 ShowWindowParentID(sender As Object, evt As Ext.Net.DirectEventArgs)
            Dim mb As New Ext.Net.MessageBox
            mb.Alert("ParentID", "I wish show the parent window ID here!")
            mb.Show()
        End Sub
        
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="resManagerSGCO" runat="server" Namespace="SuperaWeb.SGCO" /> 
        <ext:Button runat="server" ID="btnGetParentWindowID" Text = "Show Parent Window ID">
            <DirectEvents>
                <Click OnEvent="ShowWindowParentID">
                    <ExtraParams>
                        <ext:Parameter Name="id" Value="parentAutoLoadControl.id" Mode="Raw" />
                    </ExtraParams>
                </Click>
            </DirectEvents>
        </ext:Button>
        </form>
    </body>
    </html>
  6. #6
    Hi Daniil!

    I did what I wanted, using your tip!

    I set to a ext:hidden the ID in AfterRender event...

    thanks a lot

        <ext:Hidden runat="server" ID="txtWindowCfgID" Text="">
            <Listeners>
                <AfterRender Handler="this.setValue(parentAutoLoadControl.id);"  Delay="100" />
            </Listeners>
        </ext:Hidden>
  7. #7
    Good point.

    Though I was unable to reproduce this error:
    Runtime Error in Microsoft JScript: 'parentAutoLoadControl' is not defined.
    Here is my test case.

    Example Parent Page
    <%@ Page Language="C#" %>
    
    <%@ 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">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Window 
                ID="Window1" 
                runat="server" 
                Width="300" 
                Height="300">
                <Loader runat="server" Mode="Frame" Url="Test.aspx">
                    <LoadMask ShowMask="true" />
                </Loader>
            </ext:Window>
        </form>
    </body>
    </html>
    Example Child Page
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void GetID(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("ID", e.ExtraParams["id"]).Show();
        }
    </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>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Button runat="server" Text="Get id">
                <DirectEvents>
                    <Click OnEvent="GetID">
                        <ExtraParams>
                            <ext:Parameter Name="id" Value="parentAutoLoadControl.id" Mode="Raw" />
                        </ExtraParams>
                    </Click>
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
  8. #8
    Hi Daniil!

    I solved my problem!

    Thanks a lot for your help!

Similar Threads

  1. Replies: 2
    Last Post: Feb 01, 2012, 6:56 AM
  2. Replies: 16
    Last Post: Jul 19, 2011, 3:53 AM
  3. Replies: 1
    Last Post: Jul 07, 2011, 8:34 PM
  4. Replies: 1
    Last Post: Nov 24, 2010, 3:04 PM
  5. Closing a parent window from code behind
    By Kamal in forum 1.x Help
    Replies: 2
    Last Post: Sep 29, 2009, 8:25 PM

Posting Permissions