Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
what is user control and when this use in c#?
Posted

Look at the following link:
http://www.c-sharpcorner.com/UploadFile/jayendra/how-to-create-usercontrol-in-windows-form-application/[^]

Purpose of user controls:
http://forums.asp.net/t/1061924.aspx/1[^]

An explanation on ASP.Net user controls given below:
User controls in ASP .NET[^]
 
Share this answer
 
Comments
Mohamed Mitwalli 14-Aug-12 4:22am    
5+
Vani Kulkarni 14-Aug-12 5:40am    
Thanks :)
A user control is a kind of composite control that works much like an ASP.NET Web page —you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.

User controls are substantially easier to create, because you can reuse existing controls. They make it particularly easy to create controls with complex user interface elements.

Refer:
ASP.NET User Controls Overview[^]

If you have developed an ASP.NET Web page and would like to access its functionality throughout your application, you can make some minor alterations to the page to change it to a user control.
Refer: How to: Convert Web Forms Pages into ASP.NET User Controls[^]

How to: Create ASP.NET User Controls[^]
How to: Include ASP.NET User Controls in Web Pages[^]

[EDIT]
You can use User Control to:

1. Logically divide page
2. Need to Cache UC
3. Async loading section of page
4. Commonly used section of page in various parts of project
 
Share this answer
 
v2
Comments
Mohamed Mitwalli 14-Aug-12 4:22am    
5+
Prasad_Kulkarni 14-Aug-12 5:16am    
Thank you Mohamed!
Manas Bhardwaj 15-Aug-12 3:06am    
Correct +5!
Prasad_Kulkarni 16-Aug-12 0:10am    
Thank you Manas!
SQL
using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls using the same techniques you use for creating ASP.NET Web pages. These controls are called user controls.

A user control is a kind of composite control that works much like an ASP.NET Web page—you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.
 
Share this answer
 
Comments
Mohamed Mitwalli 14-Aug-12 4:26am    
5+
ankur15 14-Aug-12 4:32am    
thnx so now u get it what is user controls in c#.
Basically, the user control is a class designed to make a sort of custom controls, mostly for simplest ad-hoc purposes, otherwise — for the weak-minded people who think that serious programming can be done via the Designer. In other word, the user control is a class to be overridden and used for creation of a custom control with the use of the Designer, in a way similar to creation of a Form or a Window with XAML (for WPF). Naturally, like all Designer-based development, it all based on manual labor, and, hence, only suitable for pretty simple designs. It is the typical mistake of many developers to overuse/abuse the designer and pay for that by repetitive manual work which is hard to maintain.

The most serious, fundamental and important controls are done based on the Control class and some other classes.

I did not provide further detail and referenced to MDSN because the classes named "UserControl" exist in different unrelated UI libraries; and you did not mention what class do you mean, exactly. If you have further questions, I'll gladly try to answer.

—SA
 
Share this answer
 
Comments
Mohamed Mitwalli 14-Aug-12 4:21am    
5+
Sergey Alexandrovich Kryukov 14-Aug-12 11:25am    
Thank you, Mohamed.
--SA
Manas Bhardwaj 15-Aug-12 3:06am    
5+
Sergey Alexandrovich Kryukov 15-Aug-12 13:07pm    
Thank you, Manas.
--SA
A UserControl is a class you can create that derives from Control and thus can be displayed, or included in the Toolbox just like any of the standard controls - TextBox, Button and Treeview for example.

I use them to create new composite controls: for example I have a UserControl which combines a ToolStrip and a ListBox and provides a lot of functionality to add, remove and amend items in the listbox. When I need to list some contents, I just drop it on the form and it does the work for me - I had to do a little extra work to create it in making it as generic as I could (and it wasn't a whole lot), but once I'd done that I save time and effort every time I need it, because I know it works and don't have to re-invent the wheel.
 
Share this answer
 
Comments
Mohamed Mitwalli 14-Aug-12 4:23am    
5+
 
Share this answer
 
Comments
Mohamed Mitwalli 14-Aug-12 4:25am    
5+
user-controls = controls that are designed and coded by user.
user-controls are used for purpose of re-use design & functionality.

there are different base controls available in .net
eg. label, grid, panel, textbox, radio button etc.

user-controls are controls which have generally more-than one base controls inside.
and perform some kind of task with/without different parameters/properties

eg.
suppose, for a manufacturing company you are developing ERP,
you need calculator to calculate 'volume of 3d-rectangular job'.
suppose you will need this cal-c in all production forms & invoice forms
then for achieve this re-usability 
create usercontrol,
that have 3 textboxes for input l-b-h and 4th label for display result.
now, code it
and build your application you will get this user-control in toolbox
now, you can use it in different forms by just drag & drop it to your form.


you can create different properties & methods of usercontrol.
Happy coding!
:)
 
Share this answer
 
v2
Comments
Mohamed Mitwalli 14-Aug-12 4:25am    
5+
Aarti Meswania 14-Aug-12 4:30am    
thank you! :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Aug-12 11:27am    
Would be good to have a reference to WPF, too, but OP did not tell us what is he interested in. I voted 4.
--SA
Mohamed Mitwalli 14-Aug-12 16:30pm    
Thank you SA :)
Prasad_Kulkarni 16-Aug-12 2:11am    
Good links +5!
Mohamed Mitwalli 16-Aug-12 4:30am    
Thank you Prasad :)
Hi,

So many Articles/ Discussion/Information on internet,

MSDN Articles on User Controls[^]

Hope this information helps you,

Thanks
-Amit Gajjar
 
Share this answer
 
v5
Comments
Mohamed Mitwalli 14-Aug-12 4:23am    
5+
AmitGajjar 14-Aug-12 4:26am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900