User Controls and Custom server control

Posted by Senthilns2005 under Interview Questions on 6/14/2011 | Points: 10 | Views : 4832 | Status : [Member] | Replies : 4
what is Difference between User Controls and Custom server control with Example ?

Regards
N.Senthilkumar



Responses

Posted by: Robin_ahuja2008 on: 6/15/2011 [Member] Starter | Points: 25

Up
0
Down
Please check the link
http://oreilly.com/catalog/progaspdotnet/chapter/ch14.html

Regards,
Robin Ahuja

Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 6/16/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Refer this,

http://support.microsoft.com/kb/893667

Regards,
Susan

Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 6/16/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
There are two main categories of creatable Web controls. User controls are more simple to create, but custom controls are more simple to use. The extra effort that goes into creating custom controls pays off for the developer using the control at design time.

User controls are the natural evolution of include files, which are well known by old school ASP developers. If you're still using server-side include files in ASP.NET, it's time to leave them behind and dig into user controls, which are better in virtually every way. User controls are little more than a snippet of a Web page that can be dragged and dropped anywhere to duplicate bits of user interface and the associated functionality. (In fact, it's not difficult to convert an entire Web page into a user control.) They are object-oriented, so public properties can be added, as well as methods and events, to allow them to easily communicate with the page and other controls on the page.

User controls are saved with an ASCX file extension. Although they can be easily reused on any of the pages within the project in which they were created, there is no good way to reuse them in a different project. Another downside to user controls is that they only appear on the page at run time; at design time they appear on the page as an ugly gray box, making it difficult to envision how they'll appear to your users.

Figure 1 shows the HTML source code for a basic sidebar menu user control. A standard control like this is a navigational staple needed by virtually every page in a Web site. It would be wasteful to manually re-create such a structure over and over again for each page. Instead, simply drag this control from the Visual Studio.NET solution explorer window onto each page as needed. This example does not include any code-behind logic, but any user control can have a code-behind file of its own to contain any necessary server-side code. Figure 2 shows how the control looks on a Web page that includes a CSS style sheet to enhance the appearance.

<%@ Control Language="vb" AutoEventWireup="false" %>
<TABLE id="Table1" style="WIDTH: 136px; HEIGHT: 99px"
cellSpacing="1" cellPadding="1" width="136" border="1">
<TR>
<TD align="center">
<asp:HyperLink id="HyperLink1" runat="server" NavigateUrl="Home.aspx">Home</asp:HyperLink>
</TD>
</TR>
<TR>
<TD align="center">
<asp:HyperLink id="HyperLink2" runat="server" NavigateUrl="Products.aspx">Products</asp:HyperLink>
</TD>
</TR>
<TR>
<TD align="center">
<asp:HyperLink id="HyperLink3" runat="server" NavigateUrl="Services.aspx">Services</asp:HyperLink>
</TD>
</TR>
<TR>
<TD align="center">
<asp:HyperLink id="HyperLink4" runat="server" NavigateUrl="Contact.aspx">Contact Us</asp:HyperLink>
</TD>
</TR>
</TABLE>






Custom controls can do everything that user controls can do - and much more. The biggest drawback is that they are more challenging and complex to create. Drag and drop is not supported for the creation of these controls. Therefore, all the HTML they output must be generated via code. Pretty much all the articles & controls on this web site are examples of custom controls. In addition to run-time functionality without limits, custom controls support rich design-time functionality. They can appear on a page at design time the same way they'll appear at run time, or differently if preferred. They can be adjusted to change how they'll appear in the toolbox, and how the properties will appear in the properties window. If the properties window doesn't support the desired functionality, it can be extended with custom popup dialog boxes and other UI tricks. Custom controls are easily distributed and can be enhanced with help documentation and licensing functionality, allowing them to be sold to other developers.


Regards,
Susan

Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: NarenSelva on: 11/28/2011 [Member] Starter | Points: 25

Up
0
Down
Custom Control:

1) To be used across different applications.
2) Good for dynamic layout.
3) Doesn't have a visual interface.
4) It's a .DLL (Dynamic Linked Libraries) file.
5) It can be added to the toolbox and can be used in different applications without re-compiling.

User Control:

1) Can be used for a particular website.
2) Good for Static layout.
3) Have a visual interface.
4) It's an .ascx file.
5) It can't be added to the toolbox and it will not have design support and loaded at runtime.


Senthilns2005, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response