0

Currently, I have got 7 user controls placed on a single aspx page, some of which are created as Menu, Footer, or Header, etc.

I am just wondering if it's a good practice to always take advantage of web user controls to separate different page components. Would there be any real impact on the performance, e.g. on page load or server responsiveness, etc, if there's relatively large numbers of controls going to be used on aspx pages?

I have also noticed that @ OutputCache is an option for caching user controls, so is it good idea to apply @ OutputCache for Header, Footer and those kind of user controls?

1 Answer 1

2

Premature optimization is the root of all evil

- Donald Knuth.

Do not use output caching, or any other form of optimization unless you have evidence gained from profiling that you need to use it. Output caching is really more to prevent needing to hit a database back-end for commonly-accessed, non-personalized webpages, like a high-traffic frontpage.

There is nothing inherently wrong, performance-wise, with using UserControls - everything gets compiled behind-the-scenes into a high-performance assembly that returns text via an output buffer writer directly. The only "cost" of using a control is an additional vtable call to the Render function, and the extra bytes each control's state uses in-memory. i.e. it's negligible.

During a page's lifecycle, the step that uses the most time is invariably hitting a database or external web-service. Rendering a completed page takes around a millisecond or less. Enable output tracing if you don't believe me.

That said, I question why you're using UserControls for common site areas, like a header and footer - this is what MasterPages are for.

Sign up to request clarification or add additional context in comments.

1 Comment

I guess it's more because of the re-usability?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.