How to use the Usercontrol in Windows form application c# and what is its benifits
Give me some Idea and links ...
I want to learn more About user controls
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 14, 2012, 4:29 PM EDT
To create an instance of a user control programmatically
In the user control, be sure that the @ Control directive contains a ClassName attribute that assigns a class to the user control.
The following example sets the ClassName attribute to strongly type a user control.
Copy
<%@ Control className="MyUserControl" %>
In the page where you want to work with the user control, create a reference to the user control with the @ Reference directive.
When you create the user control programmatically, the strong type for your user control is available to the ASP.NET Web page only after you have created a reference to it. For example, the following code creates a reference to a user control created in the MyUserControl.ascx file.
Copy
<%@ Reference Control="MyUserControl.ascx" %>
Create an instance variable for the user control, using the control's class name. The class will be part of the ASP namespace.
For example, if you want to create an instance of the user control declared as class Spinner, you use syntax such as the following:
VB
Copy
Protected Spinner1 As ASP.Spinner
C#
Copy
Protected ASP.Spinner Spinner1;
Create an instance of the user control in code by calling the LoadControl method.
Assign property values as necessary, and then add the control to the ControlCollection collection of a container on the page, such as a PlaceHolder control.
The following example shows an ASP.NET Web page that loads a user control programmatically. The page includes an @ Reference directive to specify the control's file. The LoadControl method reads the file and instantiates it as a control that can be added to the page.
C#
VB
Copy
<%@ Page Language="C#" %>
<%@ Reference Control="~/Controls/Spinner.ascx" %>
Also Please refer the below links
http://msdn.microsoft.com/en-us/library/c0az2h86.aspx
http://www.c-sharpcorner.com/uploadfile/jayendra/how-to-create-user-control-in-Asp-Net/
http://msdn.microsoft.com/en-us/library/26db8ysc(v=vs.85).aspx
http://asp.net-tutorials.com/user-controls/using/
Thanks