PDA

View Full Version : [CLOSED] I wish get the parent ID in Code Behind



supera
Mar 12, 2012, 1:22 PM
Hi!

Hi! I create a window in code behind (test23.aspx code) and Im 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>

Daniil
Mar 12, 2012, 3:56 PM
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.

supera
Mar 12, 2012, 4:39 PM
Is there any example I can follow?

Daniil
Mar 12, 2012, 5:17 PM
Well, via DirectEvent ExtraParams.

<ext:Parameter Name="id" Value="parentAutoLoadControl.id" Mode="Raw" />

supera
Mar 12, 2012, 5:47 PM
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>

supera
Mar 12, 2012, 5:55 PM
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>

Daniil
Mar 12, 2012, 7:50 PM
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>

supera
Mar 13, 2012, 5:55 PM
Hi Daniil!

I solved my problem!

Thanks a lot for your help!