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

LoadXml Error

2 Answers 32 Views
RibbonBar
This is a migrated thread and some comments may be shown as answers.
Jeff Paetkau
Top achievements
Rank 1
Jeff Paetkau asked on 07 Oct 2011, 10:58 PM
Consider the following code:

<telerik:RadRibbonBar ID="Menu" runat="server" OnButtonToggle="ButtonToggle" />

private void Page_Load(object sender, System.EventArgs e)
{
    if (!IsPostBack)
    {
        String Menu_XML = new XElement("RibbonBar"
                , new XElement("Tab", new XAttribute("Text", "View")
                    , new XElement("Group", new XAttribute("Text", "Columns")
                        , new XElement("ToggleButton", new XAttribute("Text", "test"))))).ToString();
        Menu.LoadXml(Menu_XML);
    }
}
 
protected void ButtonToggle(object sender, System.EventArgs e)
{
}

Produces the following error when you toggle the button

Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: indexProduces the following error when you toggle the button


However, the following code works as expected:

<telerik:RadRibbonBar ID="Menu" runat="server" OnButtonToggle="ButtonToggle">
    <telerik:RibbonBarTab Text="View">
        <telerik:RibbonBarGroup Text="Columns">
            <Items>
                <telerik:RibbonBarToggleButton Text="Test" />
            </Items>
        </telerik:RibbonBarGroup>
    </telerik:RibbonBarTab>
</telerik:RadRibbonBar>

What am I doing wrong?

2 Answers, 1 is accepted

Sort by
0
Accepted
Kate
Telerik team
answered on 12 Oct 2011, 11:50 AM
Hi Jeff,

The error that you encounter occurs because every time the page posts back the tab, the group and the toggle button get lost. Therefore the approach that you need to apply is to create them at an earlier stage, for example OnInit. Here you can read more about how to dynamically create controls in ASP.NET.  You can also refer to the modified code below:

markup:
<telerik:RadRibbonBar ID="Menu" runat="server" OnButtonToggle="ButtonToggle">
        </telerik:RadRibbonBar>

code behind:
protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        addTab();
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 
    private void addTab()
    {
        String Menu_XML = new XElement("RibbonBar", new XElement("Tab",
                     new XAttribute("Text", "ViewCodeBehind"),
                     new XElement("Group", new XAttribute("Text", "Columns"),
                         new XElement("ToggleButton", new XAttribute("Text", "test"))))).ToString();
        Menu.LoadXml(Menu_XML);
    }
 
    protected void ButtonToggle(object sender, System.EventArgs e)
    {
    }


All the best,
Kate
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
0
Jeff Paetkau
Top achievements
Rank 1
answered on 12 Oct 2011, 10:37 PM
Thanks.
Tags
RibbonBar
Asked by
Jeff Paetkau
Top achievements
Rank 1
Answers by
Kate
Telerik team
Jeff Paetkau
Top achievements
Rank 1
Share this question
or