ASP.Net Custom controls vs. user controls: Are these two the same

前端 未结 3 1729
滥情空心
滥情空心 2020-12-11 07:02

If they are different, under what circumstances should we decide to use either approach?

Also, what is the advantage of ascx over aspx?

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 07:37

    User Controls/Composite controls

    User controls that are made up of other ASP.Net or custom controls. They are usually quite straight forward and can be created quite quickly. They Are generally not shared across projects however there are some tricks that can allow you to do this.

    Custom controls

    Custom controls are controls that you implement the UI by creating everything from the HTML output to design time support. Custom controls take much longer to make. You must use either Web.UI.Control or inherit from a sub control (Textbox for example). Custom controls are compiled to binary format to allow them to be distributed more easily. Since they are compiled they can be referenced from the toolbox in visual studio.

    There are 2 main advantages to using a control in an aspx page. Encapsulation of logic and reuseability.

提交回复
热议问题