Problem programmatically adding buttons in version 2008.1 619

4 posts, 1 answers
  1. Dave Miller
    Dave Miller avatar
    64 posts
    Member since:
    Oct 2004

    Posted 23 Jun 2008 Link to this post

    I have spent a bit of time trying to upgrade a project to version 2008.1 619 but have been getting this error:

    [ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index]
       System.Collections.ArrayList.get_Item(Int32 index) +2748189
       System.Web.UI.StateManagedCollection.System.Collections.IList.get_Item(Int32 index) +9
       Telerik.Web.StronglyTypedStateManagedCollection`1.get_Item(Int32 index) +20
    

    I have traced it down to the line: "RadEditor1.Tools[0].Tools.Insert(0, custom1);"

    in

    EditorTool custom1 = new EditorTool();
    custom1.Name = "CustomSave";
    custom1.ShortCut = "CTRL+1";
    RadEditor1.Tools[0].Tools.Insert(0, custom1);

    The help file also shows adding a button using the code below which also creates the error

    EditorTool tool = new EditorTool("Bold");
    tool.Type = EditorToolType.Button;
    RadEditor1.Tools[0].Tools.Add(tool);

    Has something been changed or is this a bug to be resolved. Any help would be greatly appreciated.

    Thanks,
    Dave
  2. Answer
    Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 24 Jun 2008 Link to this post

    Hi Dave,

    By default, RadEditor loads its internal ToolsFile.xml file with predefined tools and modules. In the latest version, we made the toolsfile.xml to be loaded on PreRender, but in the old one the tools and modules were loaded on Init, which is to early in the editor's life cycle.

    If you want to dynamically access, add or remove tools and modules in the new editor, you should call the new editor's EnsureToolsFileLoaded() method and everything should work fine, e.g.


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            EditorTool tool = new EditorTool("Bold");
            tool.Type = EditorToolType.Button;
            RadEditor1.EnsureToolsFileLoaded();
            RadEditor1.Tools[0].Tools.Add(tool);

        }
    }

    Kind regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dave Miller
    Dave Miller avatar
    64 posts
    Member since:
    Oct 2004

    Posted 24 Jun 2008 Link to this post

    Rumen,

    Thanks for the reply.
     
    Indeed adding "EnsureToolsFileLoaded()" was all that was needed.

    This may be a good thing to add to the new manual  under the "Buttons" section as it still shows the old method.

    Best regards,
    Dave
  5. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 25 Jun 2008 Link to this post

    Hi Dave,

    Thank you for your suggestion.

    We are currently updating RadEditor's documentation and we will provide information about the new EnsureToolsFileLoaded method.

    Kind regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top