Dynamic Tabs - Telerik.Web.UI.ControlItem.get_Index() Object reference not set

3 posts, 0 answers
  1. Robert
    Robert avatar
    37 posts
    Member since:
    Feb 2012

    Posted 09 Mar 2012 Link to this post


    I have a solution that adds tabs and page views dynamically, then based on postback criteria may potentially remove those tabs and add new ones.

    The sequence is:
    - First Render:
        - Build Tab with PageViewID set
        - Build PageView using known PageViewID
        - Add control to PageView
        - Add PageView to MultiPageView
    - Postback (no changes of tab):
        - Find PageView and Add Control
    (all working fine so far no matter how many postbacks)
    - Postback (changes to tabs):
        - Find PageView
        - Find Tab
        - Remove Tab
        - Remove PageView
        - Perform sequence as per First Render except with different Tab and PageView

    Then during this postback there is some code changing tab selection. This code sets  this.{Tab}.Selected = true;
    An exception is thrown at this point from the Telerik libraries. 

    System.NullReferenceException occurred
      Message=Object reference not set to an instance of an object.
           at Telerik.Web.UI.ControlItem.get_Index()
           at Telerik.Web.UI.RadTab.set_Selected(Boolean value)

    I have tried when adding +/ removing to change the SelectIndex of the RadTabStrip. I have tried selecting another (known to exist) tab. some general stuff like:


    (tabStrip.Tabs.Count > 1)


        tabStrip.Tabs[0].Selected = true;

        tabStrip.Tabs[0].PageView.Selected = true;


    Nothing I have tried is preventing this exception. I have not seen any demo or example of adding then removing + adding during page life cycles.

    The other question I have is why do the RadTabStrip and MultiPageView recreate the dynamic tabs. This is not like normal ASP.NET controls which you must recreate every postback in the same order. Is there a way to prevent automatic recreation of tabs?


  2. Robert
    Robert avatar
    37 posts
    Member since:
    Feb 2012

    Posted 09 Mar 2012 Link to this post

    To add a bit more context. The null object reference happens in the code behind when I access the Selected property on the tab directly. It doesn't happen when I go via the Tabs collection.


    this.Tab.Selected = true;     [error]
    this.TabStrip.Tabs[0].Selected = true;     [no error]

  3. Dimitar Terziev
    Dimitar Terziev avatar
    1268 posts

    Posted 13 Mar 2012 Link to this post

    Hi Robert,

    In order to help you identify the cause of your issue I would need more information about the exact implementation that you are using. Could you please open a support ticket and provide a sample project demonstrating the problem.

    Regarding your second question, the dynamically added tabs are recreated from the ViewState. If you set the EnableViewState property of the RadTabStrip to false and add the tabs only upon initial load they will be lost after post-back.

    All the best,
    Dimitar Terziev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top