Now I have an object which I need to add to multiple tabs, but if I add it to multiple tabs it's only visible to the the last tab it's added to. This has probably to do with Object by reference, but how can I work around this? The object is not cloneable. Any suggestions?
That won't work because these webcontrols are pretty complicated and can't be used with a new. I'm trying to add datatypes to my tab like this:
//Add the MNTP images to the details tab.
DataTypeDefinition MNTPImagesDatatype = DataTypeDefinition.GetDataTypeDefinition(Configuration.MNTPArticleImages);
_MNTPImages_DataEditor = (MNTP_DataEditor)((AbstractDataEditorControl)MNTPImagesDatatype.DataType.DataEditor).Control;
_MNTPImages_DataEditor.PreRender += new EventHandler(MNTPImages_PreRender);
PlaceHolderImage.Controls.Add(_MNTPImages_DataEditor);
This webcontrol needs to be added to multiple tabs and I don't want to use this piece of code every time because it's pretty heavy. Would like to get the datatype once and add it to multiple tabs.
I'm using 10 tinyMCE editors on a custom page and for each editor I do the following:
//Add TinyMCE to the tab.
_defaultEditorNL = (TinyMCE)defaultEditorDatatype.DataType.DataEditor;
PlaceHolderNLLongDescription.Controls.Add(_defaultEditorNL);
This is pretty database intensive I think. Can I get the value just once and copy to other placeholders?
I'm pretty sure that this isn't possible - a control is only meant to be in a single container. This is an ASP.NET restriction, not an Umbraco one. Each instance of a control in the page has it's own state, including its parent control and child controls.
The real way to improve this is a deep look at the rich text control itself, to identify the data that is shareable and allow it to cache. This isn't easy however.
If you want to have multiple controls, you need to create multiple controls... simple as that. Otherwise it would be impossible to reference which control your working with. Why not just create a method to create you the control, then call that method for each one you want?
Thanks for clearing that up. I knew it was an ASP.Net thing, but since my problem was related to Umbraco (and the community gives much better responses that any other) I thought I would ask it here.
Using a method might be a good idea, but if I need the TinyMCE DataEditor 10 times I would still need to call that method 10 times and there is no performance boost. Wouldn't it be possible to clone it somehow so I just fetch it once from the database, clone or copy it (or some other way it's not object by reference anymore) and add it to all the placeholders I need?
I wouldn't be worried about creating a web control 10x in regards to performance... hundreds of controls could be created on each page, it's not an issue. Even though TinyMCE looks big on the front end and consumes a few resources such as javascript/css/etc..., it is a tiny web control in the .Net world.
Cloning a control would require a much higher overhead and performance loss because you would have to deep copy all of it's properties.
I think I've just noticed what you mean by performance and creating a control from the database:
//Add the MNTP images to the details tab. DataTypeDefinitionMNTPImagesDatatype=DataTypeDefinition.GetDataTypeDefinition(Configuration.MNTPArticleImages); _MNTPImages_DataEditor =(MNTP_DataEditor)((AbstractDataEditorControl)MNTPImagesDatatype.DataType.DataEditor).Control; _MNTPImages_DataEditor.PreRender+=newEventHandler(MNTPImages_PreRender); PlaceHolderImage.Controls.Add(_MNTPImages_DataEditor);
this is actually not a great way to be constructing this control. You don't need to go to the database and use the api to create the raw control. Just instantiate the raw control manually:
var editor = new MNTP_DataEditor(); editor.ID = "SomeID"; //do other stuff with editor
@Shannon The problem is I don't want to use the raw control, but the actual datatype (with all the prevalue values) so using your example is the only way to really do it. Your MNTP has an empty constructor, but the the TinyMCE DataEditor doesn't even have that (it requires IData and the Configuratation files in the constructor).
I've tested it a bit more and you're right the TinyMCE editor isn't making the page a lot slower. However after removing 2 MNTP DataEditors the custom page does become faster. Does this have something to do with the picker that uses the images preview? This seems to make it a lot slower. Does it use umbraco cache because if it doesn't that's probably the problem why my page is so slow.
When you are creating controls, this is server side. When your actual page is slow (as in sluggish to operate), this is client side. If the page is just taking a long time to load before you see anything then this is either server side performance or a bad network connection.
How many images do you have in each picker? Each image will be an additional request... so yeah, if you have tons of images picked it will obviously be slower.
I have like 10 images and it's only slow while loading the page or while doing a postback (save button) so its probably server side. If I only have 2 images it's already a lot faster so I guess that's the problem. Maybe a nice feature to use the media cache in MNTP for uComponents v2?
Add webcontrol to multiple controls
Hello,
I'm building a custom section with tabs and in order to add webcontrols to these tabs you need to do the following:
Now I have an object which I need to add to multiple tabs, but if I add it to multiple tabs it's only visible to the the last tab it's added to. This has probably to do with Object by reference, but how can I work around this? The object is not cloneable. Any suggestions?
Jeroen
Is it an instantiable object? If so, then why not create a new instance of it for each tab?
dataTab.controls.Add(new Webcontrol); ??
That won't work because these webcontrols are pretty complicated and can't be used with a new. I'm trying to add datatypes to my tab like this:
This webcontrol needs to be added to multiple tabs and I don't want to use this piece of code every time because it's pretty heavy. Would like to get the datatype once and add it to multiple tabs.
Jeroen
I'm using 10 tinyMCE editors on a custom page and for each editor I do the following:
This is pretty database intensive I think. Can I get the value just once and copy to other placeholders?
Jeroen
I'm pretty sure that this isn't possible - a control is only meant to be in a single container. This is an ASP.NET restriction, not an Umbraco one. Each instance of a control in the page has it's own state, including its parent control and child controls.
The real way to improve this is a deep look at the rich text control itself, to identify the data that is shareable and allow it to cache. This isn't easy however.
If you want to have multiple controls, you need to create multiple controls... simple as that. Otherwise it would be impossible to reference which control your working with. Why not just create a method to create you the control, then call that method for each one you want?
... this is an ASP.Net thing, not an Umbraco thing.
Thanks for clearing that up. I knew it was an ASP.Net thing, but since my problem was related to Umbraco (and the community gives much better responses that any other) I thought I would ask it here.
Using a method might be a good idea, but if I need the TinyMCE DataEditor 10 times I would still need to call that method 10 times and there is no performance boost. Wouldn't it be possible to clone it somehow so I just fetch it once from the database, clone or copy it (or some other way it's not object by reference anymore) and add it to all the placeholders I need?
Jeroen
I wouldn't be worried about creating a web control 10x in regards to performance... hundreds of controls could be created on each page, it's not an issue. Even though TinyMCE looks big on the front end and consumes a few resources such as javascript/css/etc..., it is a tiny web control in the .Net world.
Cloning a control would require a much higher overhead and performance loss because you would have to deep copy all of it's properties.
I think I've just noticed what you mean by performance and creating a control from the database:
this is actually not a great way to be constructing this control. You don't need to go to the database and use the api to create the raw control. Just instantiate the raw control manually:
@Shannon The problem is I don't want to use the raw control, but the actual datatype (with all the prevalue values) so using your example is the only way to really do it. Your MNTP has an empty constructor, but the the TinyMCE DataEditor doesn't even have that (it requires IData and the Configuratation files in the constructor).
I've tested it a bit more and you're right the TinyMCE editor isn't making the page a lot slower. However after removing 2 MNTP DataEditors the custom page does become faster. Does this have something to do with the picker that uses the images preview? This seems to make it a lot slower. Does it use umbraco cache because if it doesn't that's probably the problem why my page is so slow.
Jeroen
there's 2 things here with performance:
When you are creating controls, this is server side. When your actual page is slow (as in sluggish to operate), this is client side. If the page is just taking a long time to load before you see anything then this is either server side performance or a bad network connection.
How many images do you have in each picker? Each image will be an additional request... so yeah, if you have tons of images picked it will obviously be slower.
I have like 10 images and it's only slow while loading the page or while doing a postback (save button) so its probably server side. If I only have 2 images it's already a lot faster so I guess that's the problem. Maybe a nice feature to use the media cache in MNTP for uComponents v2?
Jeroen
is working on a reply...