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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jul 14, 2012, 8:29 PM
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