Hi Adam,
I think we found why it is going wrong and fixed it. I'll try and explain.
Say we have
int pos = 0;
ceEditor.InsertToolControl(pos, "MyButton", ctrl);
The above will work fine.
Now we change it to:
int pos = ceEditor.ToolControls.IndexOf("Unlink") + 1;
ceEditor.InsertToolControl(pos, "MyButton", ctrl);
We can't save our content anymore.
Say that the pos it gave back was 20 (as an example) So just to test we say:
int pos = 20;
ceEditor.InsertToolControl(pos, "MyButton", ctrl);
Now the entire editor will crash! It won't just not save our current content, but it actually crashes on build up. Odd one would say given that if we before using ToolControls.IndexOf had been given a position of 20 we should be able to add it directly as well not? Well...
If we do this:
int pos = ceEditor.ToolControls.IndexOf("Unlink") + 1;
pos = 0;
ceEditor.InsertToolControl(pos, "MyButton", ctrl);
The result becomes that the editor will be build up without it crashing, but we can not save our contents anymore.
In short, it seems that ToolControls.IndexOf() does something more then just give us back an Index. it somehow changes the ceEditor object to allow us to insert a control somewhere inbetween. And that is exactly the problem why our text disapears.
Our ceEditor is an Object nested 3 deep inside user controls. We have an Admin.aspx which can create an Editor User Control, which can create 0, 1 or multiple "Wysiwyg" user controls. That last control has the CuteEditor for us. So it's nested quite deep. This for us is needed as the admin.aspx can build up different things then just the editor to edit websites in. And the editor itself can dynamically based on what page it edits change itself to include 0 to n CuteEditors.
We checked the ID with and without ToolControls.IndexOf being called and this is what happens:
Without ToolControls.IndexOf() the ID of the Editor is:
BecoCMSEditor$inhoud$ceEditor
Which is good. That means we talk to the same object later on when saving.
Now we call ToolControls.IndexOf() in some way and the ID of the Editor becomes:
inhoud$ceEditor
So the object has been changed just by calling ToolControls.IndexOf().
Due to this it seems that we can't call the original .text property anymore. Now part of this of course is our own problem. But it's puzzling why the ID and CuteEditor object seems to be modified to find an Index. And without doing that the object refuses to accept any inserts except at the start of it. We managed to fix it by adding the button directly on creation of the user object, while it's ID is set later after creation. Before we both added the button and set it's ID after creation.