Kyle K
Kyle K

Reputation: 141

Reusing expensive UserControls

So we have this legacy code that displays data in a tree format. They pad each node of the tree using spacer images (...yup..ugh)

Unfortunately, the use of these images is controlled by an in-house UserControl that we're forced to use (basically just derives from Web.UI.WebControls.Image, though).

Well, turns out we have a HUGE tree with thousands of nodes, each one four levels deep or more. This means we're creating about 10,000 padding images each time we draw the page, which is taking up quite a bit of time.

My solution right now is to statically pre-allocate a large number of these Images and use those. I'm hoping there isn't any nastiness that will crop up when multiple users access the page at the same time.

However...is there any way to reuse a UserControl such that we could create just a SINGLE instance of the Image and somehow add it multiple times to the Controls collections? I tried this naively and it didn't work. The image only gets drawn a single time, for the first control it's added to the first time (probably something to do with INamingConainer stuff...?)

Upvotes: 2

Views: 201

Answers (2)

Antony Gibbs
Antony Gibbs

Reputation: 3470

Have you considered loading the contents of the tree in a backgound thread?

Upvotes: 0

djdd87
djdd87

Reputation: 68476

Just an idea, but can you not just replace the Padding Image User Control with a different user control, such as:

public DivPadder : HtmlGenericControl
{
    public DivPadder() : base("div")
    {
        this.Style.Add("padding:10px");
    }
}

Upvotes: 2

Related Questions