zanhtet
zanhtet

Reputation: 2050

why not user control?

why should be used use control template in asp.net? please, someone say me.

Can anyone tell me why I should use a Control Template over a UserControl in ASP.Net?

Upvotes: 0

Views: 127

Answers (2)

Dave Ward
Dave Ward

Reputation: 60570

If you're familiar with MVC, a User Control is like the WebForms equivalent of a partial view.

Update (when I answered, the question asked when to use a User Control...):

A server control is appropriate when you want to bundle assets and functionality for wider distribution than a single project. It is more complex to develop a server control than it is a User Control, but a server-control allows you to completely encapsulate HTML, CSS, JavaScript, images, and server-side logic within a single DLL.

Conversely, a User Control is much easier to develop, but cannot contain assets such as external CSS/JS or images. User Controls are basically just partial bits of an ASPX page.

Unless you know that you need the features of a server control, I would always recommend a User Control for simple de-duplication of content that's repeated in multiple ASPX pages.

Upvotes: 1

Tyler Treat
Tyler Treat

Reputation: 15008

A User Control enables you to create your own custom control modules. They're useful because they are reusable, meaning you don't have to duplicate a lot of code. You can embed them in ASP.net pages, and you can define methods and properties for them.

Upvotes: 0

Related Questions