[CLOSED] panel-derived custom class with child window - clent rendering order/method

  1. #1

    [CLOSED] panel-derived custom class with child window - clent rendering order/method

    The situation: I have a custom panel that needs its own popup form window. If I was doing this all inline, then I'd just set the window up at the top of the code and then it would be there when the panel is created so I can set up references on the client side. However, I haven't figured out a good way to set it up in the custom class so I can have the window already in existence when the panel's JS constructor fires.

    If I add the window to the panel's Controls collection, it gets rendered after the panel.

    Another possibility is outputting the window to the panel's ConfigOptions, but I can't figure out the necessary options to get that to serialize properly. (I would say this would be the preferred implementation if it's feasible)

    I could always work around by adding a getWindow() JS method that can find the window and reference that since I won't actually need the window until later, but I guess I'm a stickler for trying to do things the 'right' way (assuming I've even determined what that is).

    Any suggestions?
    Last edited by geoffrey.mcgill; Jan 19, 2015 at 5:00 AM.
  2. #2
    Hi,

    What about to add Window to the Form.Controls instead Controls collection of the custom class?
    this.Form.Controls.AddAt(0, myWindow);
    Vladimir Shcheglov
    Sr. Developer
  3. #3
    Well, the class doesn't have a .Form property. Using this.ParentForm.Controls yields the same result as using this.Page.Controls or this.Page.Form.Controls - "The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases." and in the constructor, this.Page is null so I can't do anything outside the class there. Also, if I try one of the custom ClientInit event methods, ASP.NET errors out with "Collection was modified; enumeration operation may not execute." (I assume that this is what the friendly debug error on the built-in methods was preventing against.) Basically, it seems to be a big no-no to modify the Controls collection of anything the class doesn't own.

    After poking at it a little further, this seems like it will work:
    this.ResourceManager.AddBeforeClientInitScript(myWindow.ToScript());
    I'm not sure that it's feasible in all cases, but I think I should be able to get away with it in this case since I can just attach the handlers to the form buttons when the custom panel constructor fires.

    Is there a way in the .ToScript() method parameters (or on the class itself) to tell it not to include the Ext.net.ResourceMgr.destroyCmp(...); in front? If so, then I could also feed the output to the ConfigOptions.
  4. #4
    Hi,

    What about the following sample? You can always to get window like
    Panel1.myWindow
    Here is the sample
    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.ComponentModel" %> 
    
    <script runat="server">
        public class CustomPanel : Ext.Net.Panel
        {
            private Ext.Net.Window myWindow;
    
            [ConfigOption("myWindow", typeof(LazyControlJsonConverter))]                
            [PersistenceMode(PersistenceMode.InnerProperty)]
            public virtual Ext.Net.Window MyWindow
            {
                get
                {
                    if (this.myWindow == null)
                    {
                        this.myWindow = new Ext.Net.Window() { LazyMode = LazyMode.Instance };
                        this.Controls.Add(this.myWindow);
                        this.LazyItems.Add(this.myWindow);
                    }
    
                    return this.myWindow;
                }
            }
            
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            [System.Xml.Serialization.XmlIgnore]
            [Newtonsoft.Json.JsonIgnore]
            public override ConfigOptionsCollection ConfigOptions
            {
                get
                {
                    ConfigOptionsCollection options = base.ConfigOptions;
                    options.Add("myWindow", new ConfigOption("myWindow", new SerializationOptions("myWindow", typeof(LazyControlJsonConverter)), null, this.MyWindow));
    
                    return options;
                }
            }
    
        }
        
        protected void Page_Load( object sender, EventArgs e )
        {
            this.Form.Controls.Add(new CustomPanel()
            {
                ID = "Panel1",
                Title = "CustomPanel",
                MyWindow = 
                {
                    Title = "MyWindow",
                    Hidden = false    
                }
            });
        }
    </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 id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
        
        </form>
    </body>
    </html>
    Last edited by geoffrey.mcgill; Jan 19, 2015 at 12:08 AM.
    Vladimir Shcheglov
    Sr. Developer
  5. #5
    Thank you - that allows me to output it in the ConfigOptions just fine, which is exactly what I was hoping for. Hopefully someday I'll understand all the json converters and serialization options.

Similar Threads

  1. Replies: 12
    Last Post: Dec 25, 2012, 12:55 PM
  2. [CLOSED] creating a custom class?
    By smmille1 in forum 1.x Premium Help
    Replies: 10
    Last Post: Jul 09, 2010, 10:31 PM
  3. [1.0] Rendering order causes problem
    By thchuong in forum 1.x Help
    Replies: 4
    Last Post: Jun 23, 2010, 2:19 AM
  4. Replies: 2
    Last Post: Apr 15, 2010, 6:33 AM
  5. How to create custom client component class?
    By jchau in forum 1.x Premium Help
    Replies: 1
    Last Post: Dec 24, 2008, 6:17 AM

Posting Permissions