PDA

View Full Version : [CLOSED] Close windows on click in UserControl loaded dynamically



Mario
Dec 09, 2014, 9:38 AM
I have this code:

WebForm1.aspx


<%@ Page Language="vb" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<script runat="server">
Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim Applicazione As New Ext.Net.UserControlLoader
Applicazione.ID = "Applicazione1"
Applicazione.Path = "WebUserControl1.ascx"
PanelApplicazione.Items.Clear()
PanelApplicazione.Items.Add(Applicazione)
End Sub
</script>

<!DOCTYPE html>

<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>
<form id="form1" runat="server">

<ext:ResourceManager runat="server" ID="ResourceManager1" />

<ext:Viewport runat="server" ID="Viewport1">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Center" />
</LayoutConfig>

<Items>
<ext:Panel ID="PanelApplicazione" runat="server" Flex="1" Width="1000" Border="false" PaddingSpec="5 0 5 0" Layout="FitLayout" />
</Items>

</ext:Viewport>

</form>
</body>
</html>


WebUserControl1.ascx


<%@ Control Language="vb" %>

<script runat="server">
Protected Sub Button1_Click(sender As Object, e As Ext.Net.DirectEventArgs)
Windows1.Show()
End Sub
</script>

<ext:Panel ID="Panel1" runat="server">
<Items>
<ext:Button runat="server" ID="Button1" Text="GO !" OnDirectClick="Button1_Click" />
</Items>
</ext:Panel>

<ext:Window runat="server" ID="Windows1" Hidden="true" >
<Items>
<ext:UserControlLoader Path="test.ascx" runat="server" ID="UserControlLoaderTest" />
</Items>
</ext:Window>


Test.ascx


<%@ Control Language="vb" %>
<script runat="server">
Protected Sub Button2_DirectClick(sender As Object, e As DirectEventArgs)
CType(Ext.Net.X.GetCtl(Me.Parent.Parent.ID), Ext.Net.Window).Hide()
End Sub
</script>


<ext:Panel ID="Panel1" runat="server" >
<Items>
<ext:Button runat="server" ID="Button2" Text="CHIUDI" OnDirectClick="Button2_DirectClick" />
</Items>
</ext:Panel>


that work perfectly:
If you click on "Go !" button and on "CHIUDI" button... the window closes without any problems.

BUT...
If you change the code for load User Control dinamically.....

WebUserControl1.ascx


<%@ Control Language="vb" %>

<script runat="server">
Protected Sub Button1_Click(sender As Object, e As Ext.Net.DirectEventArgs)
Dim Controllo As New Ext.Net.UserControlLoader
Controllo.ID = "Test1"
Controllo.Path = "Test.ascx"

Dim Finestra As New Ext.Net.Window
Finestra.ID = "FinestraTest1"
Finestra.Items.Add(Controllo)

Finestra.Render()
End Sub
</script>

<ext:Panel ID="Panel1" runat="server">
<Items>
<ext:Button runat="server" ID="Button1" Text="GO !" OnDirectClick="Button1_Click" />
</Items>
</ext:Panel>


...appears "The control with ID 'ctl03_Button2' not found" error.
I tried to play with the properties "ClientIDMode" and "IDMode", without success.

Help, please.

Daniil
Dec 10, 2014, 10:35 AM
Hi Mario,

.GetCtl() searches real control on server side. If you create a control dynamically and don't recreate it on a request, then .GetCtl() cannot find a control, because it is just absent.

Please try to use .GetCmp<>() instead.

Mario
Dec 10, 2014, 11:33 AM
Hi Danill,

I have replaced



<script runat="server">
Protected Sub Button2_DirectClick(sender As Object, e As DirectEventArgs)
CType(Ext.Net.X.GetCtl(Me.Parent.Parent.ID), Ext.Net.Window).Hide()
End Sub
</script>


with



<script runat="server">
Protected Sub Button2_DirectClick(sender As Object, e As DirectEventArgs)
CType(Ext.Net.X.GetCmp(Me.Parent.Parent.ID), Ext.Net.Window).Hide()
End Sub
</script>


but not works.... :(

Daniil
Dec 11, 2014, 8:13 AM
I guess this

Me.Parent.Parent.ID
doesn't reflect the Window's ID.

What is the value there?

Mario
Dec 11, 2014, 9:30 AM
Danill,

I believe that the problem is still before ...

the code returns this error:

The control with ID 'ctl03_Button2' not found

Maybe first you need to solve this problem.

Daniil
Dec 11, 2014, 10:38 AM
Please read these posts:
http://forums.ext.net/showthread.php?38701&p=174861&viewfull=1#post174861
http://forums.ext.net/showthread.php?20671&p=89173&viewfull=1#post89173

Mario
Dec 15, 2014, 12:59 PM
Hello Danill,

I read carefully the two links you posted ... without being able to solve my problem.

Can you please tell me directly the solution to be able to call up the sub "Button2_DirectClick" contained in Test.ascx ?

Daniil
Dec 16, 2014, 11:54 AM
If you want to use DirectEvent, then you should recreate user controls on each request. There is an example.
http://examples2.ext.net/#/XRender/UserControl/UpdateContent/

Please notice this code.

protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(CurrentControl.Text))
{
this.LoadUserControl(CurrentControl.Text);
}
}

If the user control has been already loaded, it is recreated on each request.

Investigating/reading this thread might be also very helpful.
http://forums.ext.net/showthread.php?27618