Originally Posted by
Vladimir
UserControl is rendered by UserControlRenderer is not related with main page at all
I am not sure why do you expect to get references to the main page.
UserControl is rendered in separate page and not involved to page life cycle of main page
In this case, we need to change methods of parent page also to find user control also (find user control from parent page)
If you need parent page context then you need to add user control to the page hierarchy (and do not use UserControlRenderer) or pass page reference to user control and use it as required
I have had to revert all DirectEvent/Method UserControl creation to using UserControlRender because UserControlLoader, Items.Add, Controls.Add destroy it's parent client data in DirectEvents. I would love to create UserControls reliably in the standard page-life cycle but that just has not been plausible in testing. UserControlRender has the ability to overcome this deficit and send the client new controls and attach to a parent element without breaking the parent.
If you're curious what I'm building and you think you have a better way, I'm open. Please advise a better strategy here:
http://forums.ext.net/showthread.php...-Hidden-Fields
I'm switching to a full ajax model without frequent Page refreshes which means I need to be able to create reusable UserControls reliably that can be rendered in Page_Load or DirectEvent/Method's with heavy nesting (e.g. that have their own controls with DirectEvents/Methods). So far I have found no better way than with UserControlRender so until I've been offered a better path, all I can do is test nuances and post the issues/limits I find. Passing in the Page from the lifecycle would defeat the reusable controls requirement.
Originally Posted by
Vladimir
It is not good idea because as I mentioned before, UserControlRenderer renders user control in another page context (you can render it anywhere, in http handler, web service and etc)
I'm not suggesting you break anything with regard to how UserControlRender presently works, but extend it so it is more reusable (as you say) anywhere, i.e. not just an httphandler or webservice, etc. So by anywhere, I'm expecting it to work within the page-lifecycle as well, and I've had great success with doing so too. I'm assuming a webservice or handler wouldn't call FindControl, but in a page life-cycle, you would, so it seems reasonable to me that if you are using it in the page life-cycle case, you should have access to the full Page tree. For the meanwhile, this has seemed to do the trick...
public partial class SelfRenderingPage {
public override Control FindControl( string id ) {
var ctl = base.FindControl( id );
if( ctl != null )
return ctl;
var Page = HttpContext.Current.Handler as Page;
return ( Page != null ) ? Page.FindControl( id ) : null;
}
}