Dynamic loaded controls keep running even if not active

12 posts, 0 answers
  1. Hk
    Hk avatar
    45 posts
    Member since:
    Nov 2008

    Posted 30 Mar 2009 Link to this post

    I use this method to load dynamically controls to my page view:

    e.PageView.Controls.Add(someControl); 

    and I use it for every tab clicked. The problem is that once the control was loaded, its life cycle occurs in every postback, even if it's not the current loaded control. For example, if I load A Control and then B Control, A lifecycle is still performed fully in every postback.

    I did try to find a solution by checking from each control, if this is the control that is now selected in the tabStrip. The porblem is that the tabStrip_onClick occurs already AFTER the page_load and other lifecycle events occurs, so the current selected control is not updated correctly.

    Two questions:
    1. From what I read, you are known with this issue. Are you about to fix it in the coming versions ?
    2. Do you have any other suggestions for a work around to solve it ?

    Thanks,
    Hadar
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 30 Mar 2009 Link to this post

    Hello Hk,

    This behavior is by design. It is implemented so for cases where the developer needs access to controls from different (unselected) pages. If you don't need this behavior you can omit the multipage control and load your controls dynamically during the TabClick event.

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Pierre-Luc
    Pierre-Luc avatar
    5 posts
    Member since:
    Jan 2009

    Posted 10 Apr 2009 Link to this post

    Hello Albert,

    I'm in the same situation that Hk and I want to know what do you mean by "omit the MultiPage control"? Do you mean not registering the MultiPage_PageViewCreated event to prevent other pageviews to be reloaded during each postback?

    Based on the "load on demand" example here :
    http://demos.telerik.com/aspnet-ajax/tabstrip/examples/applicationscenarios/loadondemand/defaultcs.aspx

    How would you accomplish the desired behavior?

    Thanks,
    Pierre-Luc
  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 10 Apr 2009 Link to this post

    Hello Pierre-Luc,

    By omitting the MultiPage control I meant not to use it at all. The example you referring to is loading the user controls inside the ItemCreated event. All loaded user controls are executed. My suggestion is to use a placeholder control and load your pages there during the TabClick event. Here is a code snippet:


    protected void RadTabStrip1_TabClick (object sender, RadTabStripEventArgs e)
    {
          PlaceHolder1.Controls.Add(LoadControl("UserControl" + e.Tab.Text + ".ascx"));
    }

    Sincerely yours,
    Albert
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. Pierre-Luc
    Pierre-Luc avatar
    5 posts
    Member since:
    Jan 2009

    Posted 10 Apr 2009 Link to this post

    Hello Albert,

    Thanks for your fast answer, I understand now.

    Last question, is it possible to achieve the "Load on demand" behavior using the PlaceHolder method? I mean, I want to cancel ajax requests for tabs whose corresponding usercontrols have been loaded. If you look at the example here :
    http://demos.telerik.com/aspnet-ajax/tabstrip/examples/applicationscenarios/loadondemand/defaultcs.aspx
    After clicking the three tabs, you can navigate between them without doing unnecessary postbacks. I would like to achieve the same result BUT without reloading the usercontrols and cycling through their life cycle on each postback.

    I'm not sure whether is possible to do that with the PlaceHolder since the MultiPage maintain a PageViews collection, and I suppose that's the key to navigate between tabs without postbacking.

    I hope I was clear! :)

    Thanks in advance Albert,
    Pierre-Luc
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 13 Apr 2009 Link to this post

    Hello Pierre-Luc,

    No, this is not possible. Canceling the load on demand actually relies on the fact that all controls are loaded. You cannot however skip their execution on the server side.

    Greetings,
    Albert
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  7. Monish
    Monish avatar
    3 posts
    Member since:
    Oct 2006

    Posted 20 Nov 2009 Link to this post

    Hi Albert,

        I am working on similar issue... Well, I have few pages that contains RadTabStrip and ascx in each tab... I noticed that on each postback all the ascx's are loaded!
       I tried you approach:
            protected void RadTabStrip2_TabClick(object sender, RadTabStripEventArgs e)
            {
                string userControlPath = "UserControls/" + e.Tab.Text + ".ascx";
                PlaceHolder1.Controls.Add(LoadControl(userControlPath));
            }


       but its not working... It loads the ascx(Page_Load of that ascx) but doesn't display anything !

      Adding controls to the PlaceHolder in Page_Load work - as expected....

      Am I missing out anything here?

     Another approach that I tried is wrapping the Telerik.Web.UI.RadPageView and adding a property (string) UserControlPath which will hold the path of the ascx. Then I wrapped Telerik.Web.UI.RadTabStrip and loaded the acsx in OnTabClick(RadTabStripEventArgs e) method:
           protected override void OnTabClick(RadTabStripEventArgs e)
            {
                base.OnTabClick(e);

                XYZ_PageView pageView = (XYZ_PageView)e.Tab.PageView;

                if (e.Tab.PageView != null && !string.IsNullOrEmpty(((XYZ_PageView)e.Tab.PageView).UserControlPath))
                {
                    Control userControl = Page.LoadControl(((XYZ_PageView)e.Tab.PageView).UserControlPath);
                    if (userControl != null)
                    {
                        e.Tab.PageView.Controls.Add(userControl);
                        e.Tab.PageView.Selected = true;
                        e.Tab.PageViewID = e.Tab.Text;
                    }
                }
            }

    This again doesn't show anything on the page!

    Let me know if I am going in correct direction...




    Monish.
  8. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 20 Nov 2009 Link to this post

    Hi Monish,

    Please refer to our TabStrip / Load on Demand RadPageView example that shows how to achieve your goal.

    Sincerely yours,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Monish
    Monish avatar
    3 posts
    Member since:
    Oct 2006

    Posted 21 Nov 2009 Link to this post

    Paul, 
       Thanks for the prompt reply... well, I already had a look at the "Load On Demand" option of the RadTabStrip... Few things that I noticed that I don't want in my applications are:
    1. The name of the ascxs are hardcoded in the code behind of the aspx (in Page_Load -> AddTab("Customers") which loads Customers.ascx)
    2. When you click the tab which is already loaded, the ascxs are again laoded
    3. If there is any postback in any of the ascx, it loads all the ascx again.

    I guess, we cannot avoid point 3. We will need to load all the controls which are already loaded to maintain the viewstated...

    Is there any solution/ suggestion for the above mention points?

    Thanks,
    Monish.
  10. Ben
    Ben avatar
    2 posts
    Member since:
    Aug 2009

    Posted 23 Nov 2009 Link to this post

    I found this thread while looking for different ways to load these tab controls "on load" so that each tab isn't loaded everytime.  I'm doing this for the same reason listed above, the pages were just running to slow.  I am trying to add each control to a Panel using the OnTabClick event as mentioned above. 

    This is running much faster, but I'm running into an issue with the controls disappearing on any postback (Ajaxed or not).  Any idea on what might be causing this? 
  11. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 24 Nov 2009 Link to this post

    Monish,

    Straight to your questions:

    1. The name of the ascxs are hardcoded in the code behind of the aspx (in Page_Load -> AddTab("Customers") which loads Customers.ascx)

    This is made just for the purposes of the example. You can use a switch if you'd like.

    2. When you click the tab which is already loaded, the ascxs are again laoded

    Please check if you have set the ClickSelectedTab property of the tabstrip to true by mistake.

    3. If there is any postback in any of the ascx, it loads all the ascx again.

    RadTabstrip always reloads all of its pageviews (via the PageViewCreated event of the multipage control). This means the code-behind of your page / UserControls will be fired no matter which pageview is rendered. Loading all pageviews is essential for the server controls living in the page views. If we don't load them every time viewstate will be corrupted and postback events won't fire.

    Ben, you should add your controls in PageViewCreated event of the multipage control, but not on TabClick.

    Greetings,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Ben
    Ben avatar
    2 posts
    Member since:
    Aug 2009

    Posted 24 Nov 2009 Link to this post

    The example at the following URL seems to be working for me.  I think the key was creating the control in both the TabClick and Page_Load.

    http://www.telerik.com/support/kb/aspnet-ajax/tabstrip/loading-user-controls-dynamically-on-tabclick-and-postback-from-loaded-user-control.aspx
Back to Top