This is a migrated thread and some comments may be shown as answers.
FAQ RadPanelBar with sub questions receiving error 'this.getLinkElement() is null or not an object'
1 Answer 20 Views
This is a migrated thread and some comments may be shown as answers.
Andy Aichele
Top achievements
Rank 1
Andy Aichele asked on 30 Jul 2009, 02:55 PM

We are trying to use the RadPanelBar to create an FAQ.  The result intended would have the question in the in the panel bar and when you click on it, the answer is shown in the expanded section.  In the answer we also want to have some ‘See also’ questions that would be also be panel items that can be expanded to show the answer.  We are running into a problem on expanding the ‘See Also’ answers.  When we click on the ‘See Also’ answer, the JavaScript error “this.getLinkElement() is null or not an object” occurs.  The generation of the RadPanelBar is all generated in the code-behind.  The code is as follows:

 

HTML

            <td>

                <telerik:RadPanelBar ID="TestPanelBar" runat="server" Width="100%" Height="100%" Style="white-space: normal" ExpandMode="SingleExpandedItem" AllowCollapseAllItems="true" EnableEmbeddedSkins="false">

                </telerik:RadPanelBar>

            </td>

 

 

Code- Behind

 

            for (int i = 0; i < 10; i++)

            {

                Telerik.Web.UI.RadPanelItem questionItem = new Telerik.Web.UI.RadPanelItem(string.Format("{0} Question", i.ToString()));

                Telerik.Web.UI.RadPanelItem answerItem = new Telerik.Web.UI.RadPanelItem();

                answerItem.Controls.Add(new Label() { Text = "this is the answer" });

 

                for (int j = 0; j < 3; j++)

                {

                    Telerik.Web.UI.RadPanelItem relatedQuestionItem = new Telerik.Web.UI.RadPanelItem(string.Format("See Also {0}", j.ToString()));

                    Telerik.Web.UI.RadPanelItem relatedAnswerItem = new Telerik.Web.UI.RadPanelItem();

 

                    relatedQuestionItem.Width = Unit.Percentage(95);

                    relatedAnswerItem.Width = Unit.Percentage(95);

 

 

                    Label answerLabel = new Label();

                    answerLabel.Text = string.Format("See Also Answer {0}", j.ToString());

                    relatedAnswerItem.Controls.Add(answerLabel);

 

                    relatedQuestionItem.Items.Add(relatedAnswerItem);

                    answerItem.Items.Add(relatedQuestionItem);

 

                }

 

                answerItem.Expanded = true;

 

                questionItem.Items.Add(answerItem);

 

                TestPanelBar.Items.Add(questionItem);

                TestPanelBar.Width = Unit.Percentage(100);

            }

 

            TestPanelBar.Items[0].Expanded = true;

 

 

The exact line of code that is causing the problem is relatedAnswerItem.Controls.Add(answerLabel);.  As soon as we add a control to the RadPanelItem, this error occurs.

 

Is there a way to add a control (note we are adding a user control, not a label, the code is above is so you can reproduce the error) to a RadPanelItem and still be able to add a ‘sub’ item.  Or do you have another suggestion how to accomplish this.

1 Answer, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 31 Jul 2009, 11:30 AM
Hi Andy,

Please find below your modified code snippet that works as expected.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Telerik.Web.UI; 
 
public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        for (int i = 0; i < 10; i++) 
        { 
            RadPanelItem questionItem = new RadPanelItem(string.Format("{0} Question", i.ToString())); 
            TestPanelBar.Items.Add(questionItem); 
            TestPanelBar.Width = Unit.Percentage(100); 
 
            RadPanelItem answerItem = new RadPanelItem(); 
            questionItem.Items.Add(answerItem); 
 
            RadPanelItem answerItem_child = new RadPanelItem(); 
            answerItem.Items.Add(answerItem_child); 
 
            Label lbl = new Label(); 
            lbl.Text = "this is the answer"
            answerItem_child.Controls.Add(lbl); 
 
            answerItem.Expanded = true
 
            for (int j = 0; j < 3; j++) 
            { 
                RadPanelItem relatedQuestionItem = new RadPanelItem(string.Format("See Also {0}", j.ToString())); 
                relatedQuestionItem.Width = Unit.Percentage(95); 
                answerItem.Items.Add(relatedQuestionItem); 
 
                RadPanelItem relatedAnswerItem = new RadPanelItem(); 
                relatedAnswerItem.Text = "123"
                relatedAnswerItem.Width = Unit.Percentage(95); 
                relatedQuestionItem.Items.Add(relatedAnswerItem); 
 
                Label answerLabel = new Label(); 
                answerLabel.Text = string.Format("See Also Answer {0}", j.ToString()); 
                relatedAnswerItem.Controls.Add(answerLabel); 
            } 
        } 
        TestPanelBar.Items[0].Expanded = true
    } 
 


All the best,
Paul
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Asked by
Andy Aichele
Top achievements
Rank 1
Answers by
Paul
Telerik team
Share this question
or