[CLOSED] Page.FindControl cannot find parent by id in Page_Load of UserControl that invoked by ResourceManger.RaisePostbackEvent

Page 2 of 2 FirstFirst 12
  1. #11
    Quote Originally Posted by Daniil View Post
    In this code the "ct" should participate in the Panel1's layout.
        protected void Render_DirectClick(object sender, DirectEventArgs e)
        {
            var ct = new Container();
            var uc = Page.LoadControl("Child.ascx");
            uc.ID = "uc1";
            ct.ContentControls.Add(uc);
            Panel1.Items.Add(ct);
            ct.Render();
        }
    The problem is the Child.ascx may contain controls that have their own flex that are supposed to be based off the Parent's Layout (in this case Panel1). If I generically render a Container, the children in the UserControl will not participate properly. The sample you provided is fine, but the api I'm trying to create looks as follows (presently updated to use your suggestion):
            /// <summary>
            /// Add a User Control during a Direct Event that needs to be Rendered to Page, like adding a Bin object.
            /// To Replace the existing, use same CtlName; To add new each time, make ctlName unique
            /// </summary>
            public static void AddDirectControl( this AbstractContainer Parent, string ucPath, string ctlName, bool items = false, BindFn bindFn = null, bool Register = false ) {
    
    
                var uc = Parent.Page.LoadControl( ucPath );
                uc.ClientIDMode = System.Web.UI.ClientIDMode.Predictable;
                uc.ID = ctlName;
    
    
                var comp = new Container();
                comp.ContentControls.Add( uc );
    
    
                // Give a chance to bind before adding the control
                if( bindFn != null )
                    bindFn( uc );
                DirectRendering = true;
                if(items)
                    Parent.Items.Add(comp);
                 else
                    Parent.ContentControls.Add(comp);
                comp.Render();
                DirectRendering = false;
    
    
                if( Register )
                    RegisterUserControl( Parent, ucPath, uc.ClientID, ClientIDMode.Predictable );
            }
    The present challenge I'm trying to work out is this api above needs to support bool items in the same way UserControlRenderer does. That is, if true, Parent.Items.Add versus Parent.ContentControl.Add if false. The problem is a just adding a generic Container is prohibitive to the design goal.

    UserControlLoader would be perfect because it handles Content or Items perfectly. That's why I'd hoped to the problem I showed here: http://forums.ext.net/showthread.php...nderMode-AddTo UserControlLoader RenderMode.AddTo would have been the end-all solution. But you told me, no, you may not support this. So I'm back to the drawing board. There's got to be some way to render a UserControlLoader to a Parent without introducing an arbitrary container but also without rerendering the parent, but how? Please advise.
    Last edited by michaeld; Dec 24, 2013 at 2:26 AM.
  2. #12
Page 2 of 2 FirstFirst 12

Similar Threads

  1. WakeUp parent page on usercontrol event
    By immanegiuv in forum 1.x Help
    Replies: 1
    Last Post: Dec 02, 2011, 10:36 AM
  2. Replies: 16
    Last Post: Jul 19, 2011, 3:53 AM
  3. Replies: 3
    Last Post: Aug 02, 2010, 11:06 AM
  4. Replies: 16
    Last Post: Jun 24, 2010, 2:41 PM
  5. Replies: 6
    Last Post: Mar 12, 2010, 12:34 AM

Posting Permissions