Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 22, 2010 @ 11:33
    Jeroen Breuer
    0

    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:

    dataTab = TabViewDetails.NewTabPage("NL");
    dataTab.Controls.Add(Webcontrol);

    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

  • Greg Berlin 818 posts 634 karma points
    Sep 22, 2010 @ 14:34
    Greg Berlin
    0

    Is it an instantiable object?  If so, then why not create a new instance of it for each tab?

    dataTab.controls.Add(new Webcontrol); ??

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 22, 2010 @ 16:07
    Jeroen Breuer
    0

    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.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 28, 2010 @ 14:08
    Jeroen Breuer
    0

    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?

    Jeroen

  • James Telfer 65 posts 165 karma points
    Sep 30, 2010 @ 03:42
    James Telfer
    0

    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.

     

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Sep 30, 2010 @ 04:39
    Shannon Deminick
    0

    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?

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Sep 30, 2010 @ 04:39
    Shannon Deminick
    0

    ... this is an ASP.Net thing, not an Umbraco thing.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 30, 2010 @ 09:24
    Jeroen Breuer
    0

    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

     

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Sep 30, 2010 @ 10:52
    Shannon Deminick
    0

    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.

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Sep 30, 2010 @ 10:55
    Shannon Deminick
    0

    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.
    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 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
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 30, 2010 @ 11:15
    Jeroen Breuer
    0

    @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

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Sep 30, 2010 @ 11:23
    Shannon Deminick
    0

    there's 2 things here with performance:

    • server side performance
    • Client side 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.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 30, 2010 @ 11:29
    Jeroen Breuer
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft