[CLOSED] Different behaviors in DirectEvent between UserControlLoader and UserControl

  1. #1

    [CLOSED] Different behaviors in DirectEvent between UserControlLoader and UserControl

    ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test31a.ascx.cs" Inherits="Test31a" %>
    
    
    <ext:Window ID="TW" runat="server" Title="Add Something" Width="500" Modal="true">
        <Items>
    
    
            <ext:FormPanel ID="FP" runat="server" BodyPadding="5" BodyStyle="background:white;" Height="400"
                Layout="FitLayout">
                <Items>
                    <ext:Label ID="Label1" runat="server" Html="Sample Text" Padding="5" Flex="1" />
                    <ext:MultiSelect ID="MS" runat="server" HideLabel="true" 
                        BodyPadding="5" StyleSpec="padding-left:10px;" Border="false" Width="110" Height="300" ShowCheckbox="true">
                        <Items>
                            <ext:ListItem Text="1" Value="1" />
                            <ext:ListItem Text="2" Value="2" />
                            <ext:ListItem Text="3" Value="3" />
                        </Items>
                        <Listeners>
                            <Render Handler="#{MS}.setSelectedItems(#{MS}.store.getAllRange());" />
                        </Listeners>
                    </ext:MultiSelect>
                </Items>
                <Buttons>
                    <ext:Button ID="Submit" runat="server" Text="Submit" Type="Submit">
                        <DirectEvents>
                            <Click OnEvent="OnAdd">
                                <EventMask ShowMask="true" MinDelay="500" Msg="Adding..." />
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
    
    
        </Items>
    </ext:Window>

    ascx.cs
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    
    public partial class Test31a : UserControl {
        protected void Page_Load( object sender, EventArgs e ) {
            if( !X.IsAjaxRequest )
                TW.Show();
        }
    
    
        protected void OnAdd( object sender, DirectEventArgs e ) {
            var items = MS.SelectedItems;
            int len = items.Count;
            X.Msg.Alert( "Items", len.ToString() );
        }
    }
    aspx
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <script runat="server">
        protected void Page_Load( object sender, EventArgs e ) {
            var ctl = Page.LoadControl( "Test31a.ascx" );
            ctl.ID  = "TaskUC" + 1.ToString();
            Page.Controls.Add( ctl );
        }
    </script>
    
    
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Test31a</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" ViewStateMode="Enabled" ScriptMode="Debug" SourceFormatting="true" />
    
    
            <ext:Viewport ID="vp" runat="server">
            </ext:Viewport>
    
    
        </form>
    </body>
    </html>
    This version does trap in OnAdd and len does seem to contain the count of selected items.

    However, this slight change in the aspx Page_Load to the following does not.
        protected void Page_Load( object sender, EventArgs e ) {
            var ctl = new UserControlLoader( new UserControlLoader.Config() { Path = "Test31a.ascx" } );
            ctl.UserControlID = "TaskUC" + 1.ToString();
            vp.Bin.Add( ctl );
        }

    I should note also that both fail to display the alert.
    Last edited by Daniil; Sep 17, 2013 at 5:28 AM. Reason: [CLOSED]
  2. #2
    Hi @michaeld,

    Running your initial test case (without a UserControlLoader) I can state that it is not true for me:
    Quote Originally Posted by michaeld View Post
    IThis version does trap in OnAdd and len does seem to contain the count of selected items.
    It is zero for me. And, as far as I can see, it should be zero, because you add a Window in the Page.Controls. It means it is not falling into the <form>. With this:
    this.Form.Controls.Add( ctl );
    the selected items get submitted.

    As for a UserControlLoader. It seems to be working for me without any changes.

    Quote Originally Posted by michaeld View Post
    I should note also that both fail to display the alert.
    You should call the Show method.
    X.Msg.Alert("Items", len.ToString()).Show();
    Last edited by Daniil; Sep 10, 2013 at 5:11 AM.
  3. #3
    Quote Originally Posted by Daniil View Post
    Running your initial test case (without a UserControlLoader) I can state that it is not true for me:

    It is zero for me. And, as far as I can see, it should be zero, because you add a Window in the Page.Controls. It means it is not falling into the <form>.
    This strategy was at the advice of vladimir in http://forums.ext.net/showthread.php...endering/page2

    He may not have considered the post-back consequences or I may have misunderstood his direction. I'll consider instead your suggestion of this in the future:
    Quote Originally Posted by Daniil View Post
    With this:
    this.Form.Controls.Add( ctl );
    the selected items get submitted.
    Ultimately this should address my non-sample code that shared the same problem.

    Quote Originally Posted by Daniil View Post
    As for a UserControlLoader. It seems to be working for me without any changes.
    This was what I was trying to establish.

    Quote Originally Posted by Daniil View Post
    You should call the Show method.
    X.Msg.Alert("Items", len.ToString()).Show();
    Sorry. My intuition keeps failing me that the Alert is returning an object; that it's not a method. I often manage to forget the Show() part. Thanks for the reminder.
    Last edited by michaeld; Sep 10, 2013 at 7:38 AM.
  4. #4
    Quote Originally Posted by michaeld View Post
    This strategy was at the advice of vladimir in http://forums.ext.net/showthread.php...endering/page2

    He may not have considered the post-back consequences or I may have misunderstood his direction.
    Well, he didn't mean adding direct to Page.Controls. So, if you need to get the controls submitted, please add them to Form. A Form is inside a page. So, it doesn't conflicts with the Vladimir's suggestion.

    Quote Originally Posted by michaeld View Post
    Sorry. My intuition keeps failing me that the Alert is returning an object; that it's not a method. I often manage to forget the Show() part. Thanks for the reminder.
    The same happens for me as well sometimes:)

Similar Threads

  1. Replies: 3
    Last Post: Sep 05, 2013, 8:18 AM
  2. Replies: 4
    Last Post: Apr 24, 2013, 4:02 AM
  3. [CLOSED] [#80] UserControlLoader
    By softmachine2011 in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Dec 20, 2012, 1:02 PM
  4. Replies: 6
    Last Post: Dec 06, 2012, 4:03 PM
  5. DirectEvent and Daynamic UserControl
    By HosseinHelali in forum 1.x Help
    Replies: 1
    Last Post: Jun 28, 2011, 11:57 AM

Posting Permissions