Dynamically adding a listener to a panel in code behind

  1. #1

    Dynamically adding a listener to a panel in code behind

    I'm having trouble trying to dynamically add a listener to a panel that I have just created dynamically. I have used the code below to try to add a listener but I doesn't seem to pick up the event. Any help appreciated.

    Using Ext.NET 3.0.0


    <%@ Page Language="C#"  %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Ext.Net.Panel panel = new Ext.Net.Panel
            {
                ID = "Panel1",
                Title = "Panel 1",
                Height = 50,
                Width = 200,
                X = 200,
                Y = 200,
                Border = true,
                Draggable = true
            };
    
            panel.AddTo(winMain);
            panel.Listeners.Move.Handler = "Ext.Msg.alert('Confirm', Ext.String.format('You Clicked {0}', this.id));";
        }
        
    
    </script>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <form id="form1" runat="server">
    
            <ext:Window ID="winMain" runat="server" Width="1000" Height="700" Layout="AbsoluteLayout">
    
            </ext:Window>
    
        </form>
    </body>
    </html>
  2. #2
    It's possible to overcome the issue by replacing
    panel.AddTo(winMain);
    by
    winMain.Items.Add(panel);
  3. #3
    Thanks that seems to have done the trick.
  4. #4
    You're welcome.
  5. #5
    Strange, if listener is defined before invoking Panel's AddTo it works.

    Let's gonna wait a position from Ext.Net Team.

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Ext.Net.Panel panel = new Ext.Net.Panel
            {
                ID = "Panel1",
                Title = "Panel 1",
                Height = 50,
                Width = 200,
                X = 200,
                Y = 200,
                Border = true,
                Draggable = true
            };
    
            panel.Listeners.Move.Handler = "Ext.Msg.alert('Confirm', Ext.String.format('You Clicked {0}', this.id));";
            panel.AddTo(winMain);
        }
    </script>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <form id="form1" runat="server">
            <ext:Window ID="winMain" runat="server" Width="1000" Height="700" Layout="AbsoluteLayout" />
        </form>
    </body>
    </html>
  6. #6
    Hello everybody,

    The AddTo method generates a script when it is called. Therefore it doesn't take into account everything that happens after.

    During an initial page request, please avoid using the AddTo method and similar ones that generate a script. it is supposed to be used during Ext.NET AJAX requests (DirectEvents and DirectMethods).
  7. #7
    +1 to you Daniil. I tried to search about AddTo method in Ext.Net documentation, but ufortunately there is no information. Thanks for sharing that.
  8. #8
    Thanks for clarifying. That makes sense.

Similar Threads

  1. Replies: 1
    Last Post: Dec 07, 2014, 11:39 PM
  2. [CLOSED] Dynamically Adding rows to Grid Panel
    By hemantpatil in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Jan 22, 2013, 6:58 AM
  3. [CLOSED] Dynamically adding view to panel MVC
    By RCM in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 14, 2011, 6:19 PM
  4. [CLOSED] Adding UserControl dynamically in code-behind
    By wagger in forum 1.x Legacy Premium Help
    Replies: 24
    Last Post: May 17, 2011, 9:48 PM
  5. Replies: 0
    Last Post: Nov 17, 2010, 9:32 PM

Tags for this Thread

Posting Permissions