[Bug 2.3.1]: UpdateContent exception on loaded control

Page 3 of 3 FirstFirst 123
  1. #21
    This code above has been pretty reliable for rendering user controls and replacing contents, but is there a way to add a user control without rerendering its parent and destroying all the client data in the process? That is, I'd like to render the new usercontrol only and add it to the existing layout? How would I go about that?

    I attempted to use Render with the control and AddTo(parent) without much luck.
    Last edited by michaeld; Dec 01, 2013 at 11:47 PM.
  2. #22
    Hi,

    About 'X.DirectRendering', ASP,NET allows async action during page life cycle.
    That flag will be in invalid state if run controls rendering in several parallel threads

    Why don't you want to add any property to user control which indicates that user control is rendered first time?
    var uc = (MyUserControl)ctnr.Page.LoadControl( ctlPath );
    uc.IsFirstRender = true; // IsFirstRender is bool property in MyUserControl
    About 'ControlsScripting', if you update from SVN then it should be not required anymore to deactivate scripting before user control rendering

    is there a way to add a user control without rerendering its parent and destroying all the client data in the process? That is, I'd like to render the new usercontrol only and add it to the existing layout? How would I go about that?
    There is UserControlRenderer
    UserControlRenderer.Render(new UserControlRendererConfig{....});
  3. #23
    sorry , i posted my code in wrong place.
    Last edited by UnifyEducation; Dec 02, 2013 at 10:15 AM.
  4. #24
    Quote Originally Posted by Vladimir View Post
    About 'X.DirectRendering', ASP,NET allows async action during page life cycle.
    That flag will be in invalid state if run controls rendering in several parallel threads
    I am not aware upon any condition in which typical WebForms has this happen? Are you thinking Asynch pages perhaps?

    Quote Originally Posted by Vladimir View Post
    Why don't you want to add any property to user control which indicates that user control is rendered first time?
    var uc = (MyUserControl)ctnr.Page.LoadControl( ctlPath );
    uc.IsFirstRender = true; // IsFirstRender is bool property in MyUserControl
    True, I could extend System.Web.UI.UserControl to support this property. Personally, though, it seems more natural to me that an ajax library should provide this extension class as part of an all in one solution and set this value automatically, but all I can do is suggest this to you. As it is, the more I use DirectEvents to construct controls dynamically without refresh, the more I'm extending over Ext.Net to create my own library of extensions to more naturally support reliable user control creation so that if I have to transfer coding responsibilities over to new programmers, they will be be able to reliably avoid some of the pitfalls I've run into. So far, I've found UserControlRender the most reliable control renderer.


    Quote Originally Posted by Vladimir View Post
    About 'ControlsScripting', if you update from SVN then it should be not required anymore to deactivate scripting before user control rendering
    Nice, I'll fix upon 2.4 as we're now dependent on using CDN.

    Quote Originally Posted by Vladimir View Post
    There is UserControlRenderer
    UserControlRenderer.Render(new UserControlRendererConfig{....});
    Yeah, I agree. I switched, http://forums.ext.net/showthread.php?27438-UserControlRendererConfig-does-not-render-some-controls
  5. #25
    Quote Originally Posted by michaeld View Post
    Quote Originally Posted by Vladimir View Post
    About 'X.DirectRendering', ASP,NET allows async action during page life cycle.
    That flag will be in invalid state if run controls rendering in several parallel threads
    I am not aware upon any condition in which typical WebForms has this happen? Are you thinking Asynch pages perhaps?
    It looks like Vladimir missed your answer. Sorry. Though, is that still actual for you or we can close the thread?
  6. #26
    This thread was one of those where we were discussing the issues with User Control reusability. Eventually the fixes Vladimir made in 2.4 and the insights I made along the way lead me to being able to create the new Delete-and-render model I posted in User Extensions.

    To start to answer your question, the original topic of this thread is about UserContent in a loaded control. The redundant call issue was remedied. The ID issue, I believe I resolved by asserting IDModes explicitly.

    But the topic evolved into other issues related to UserControl reusability when attempting to render entirely new User Controls in a DirectEvent/Method. I describe why I had to create the DirectRendering property because Ext.Net has no way to indicate a 3rd mode where the UserControl's Page lifecycle calls Page_Load and you actually want the Page_Load to bind control data.

    Typically, in a standard reloading of a page in a DirectEvent/Method, User Controls that are statically bound in the presentation layer or are explicitly dynamically added in the Page_Load lifecycle may not need to be bound because the DirectEvent/Method being called does not require the heavier binding cost of all controls to complete its purpose/function. Typically one tests X.IsAjaxRequest and skips around the binding. That is, it's not always necessary to do all the binding of all controls every time a DirectEvent/Method is fired so it makes sense to
    if(X.IsAjaxRequest) return;
    However, I had cases where the DirectEvent/Method was responsible for rendering a totally new UserControl and that was triggering it's Page_Load. In that case, while in the DirectEvent/Method, you actually want the binding of the control to happen before it's rendering because its created during the DE/M. If the developer does the typical test of X.IsAjaxRequest, it will incidentally skip the binding which is not correct. That's why I created DirectRendering and IsAjaxRequestNotRendering properties so that instead in Page_Load I could test
    if(X.IsAjaxRequestNotRendering) return;
    This property returns true only if DirectRendering==false and X.IsAjaxRequest==true so that the User Control can bind the control even though it is inside the DirectEvent/Method, just like it was an original render (GET). [in other words, bind if !X.IsAjaxRequest or (X.IsAjaxRequest and DirectRendering)].

    Vladimir said my implementation wouldn't work in parallel mode. I never got the clarification of the scenario why. I suspect it has to do with async modes now popular with latest versions of MS MVC and WebForm Asynch Pages which might make sense as I use Context.Items which may change by the time it actually returns. I'm not sure that's actually true though without looking more closely the page life-cycle between the 1st pass and the 2nd reenter. I'm pretty sure that the Page_Load events called after the original DirectEvent/Method are within the same thread though.

    Anyway, so to answer your question, close it if I'm right about that last claim. Keep it open if Vladimir has more to add.

    But since 3.0 is now on the docket, it's really time for you guys to look at the 3rd mode I've raised as an issue and look at it as a design concern. There are really 3 modes - 1. Original Load/Refresh (GET), 2. DirectEvent/Method (POST), and 3. DirectEvent/Method (POST) but now while rendering a new User Control that will call its Page_Load (which btw may have its own user controls it's rendering too).

    And in most cases, the developer needs to ask/test one thing. Do I bind or exit in Page_Load? In the 1st case yes, 2nd case no, and 3rd case yes. It might even be that the developer may need to know which of the 3 modes it's actually in.
    Last edited by michaeld; Mar 07, 2014 at 8:34 PM.
  7. #27
    Hi @michaeld,

    Thank you for the detailed answer.

    I am going to add the link to your post to the Agenda of our next group meeting on March 11.
  8. #28
    Thanks.

    While we're on this topic, I should note that I did run into other DirectEvent/Method scoping problems. I had advanced/special circumstances where, for efficiency, I needed even more information available to Page_Load events for the Page & User Controls to allow initialization to be done so the later rendered User Controls inside the DirectEvent/Method had access to that data previously initialized.

    In those cases, it would be ideal to have access to some kind of config parameters (like extraParams) that could be passed in from the client-side proxy that are scoped/accessible in the Page_Load.

    Client-side example:
    App.direct.MyDirectMethod(param1, param2, { 'SpecialCase', true } );
    Server-side example for Page's Page_Load:
    // Do the initialization if not post-back or it is post-back and 'SpecialCase' was passed from the DirectEvent/Method
    var sc = X.ExtraParams["SpecialCase"];
    if(!X.IsAjaxRequest || (sc != null && (bool)sc == true) ) {
        // Do initialization
    }
    I couldn't implement this without branching Ext.Net because it would require changes to the client Direct Method api to add the extra parameters to the postback request, extension of the X class static properties, and changes to the RaisePostBackEvent code to read the postback request for the extra parameters and set them so they are accessible to X.ExtraParams.

    For DirectEvents, it would be a little easier because ExtraParams is already a part of DirectEvent and passed to the server. Still there is no way to scope to these values from Page_Load.


    This proposed extension allows the developer to selectively run expensive initialization in Page_Loads prior to the DirectEvents/Method but only when the specific DirectEvent/Method absolutely requires it to occur (as determined by code from the client).
  9. #29
    Any update from the 11th?
  10. #30
    It's going to take some time for us to fully digest this request.

    I have spend some time reviewing the full thread again, then discuss in detail with the crew.

    We did discuss yesterday, but more review is required.
    Geoffrey McGill
    Founder
Page 3 of 3 FirstFirst 123

Similar Threads

  1. Replies: 1
    Last Post: Apr 02, 2013, 5:03 AM
  2. Replies: 1
    Last Post: Oct 10, 2012, 11:47 AM
  3. [CLOSED] [1.0] User Control loaded several times
    By FVNoel in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 07, 2011, 10:33 AM
  4. Replies: 2
    Last Post: Oct 29, 2010, 8:51 AM
  5. Replies: 2
    Last Post: Feb 10, 2010, 10:45 AM

Posting Permissions