This is a migrated thread and some comments may be shown as answers.

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

2 Answers 106 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 09 Mar 2012, 02:11 PM
Hi,

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.
  Source=Telerik.Web.UI
  StackTrace:
       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:

if

(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?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 09 Mar 2012, 03:47 PM
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.

Example:

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

0
Dimitar Terziev
Telerik team
answered on 13 Mar 2012, 05:28 PM
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.
Tags
TabStrip
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or