.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Interview Question >> ASP.Net >> Post New Question Subscribe to Interview Questions

How to use a user control in a Web Forms page

Posted By :Syed Shakeer Hussain     Posted Date :August 22, 2010    Points :10   Category :ASP.Net 
Declare the @ Register directive.

For example, use the following code.
<%@ Register TagPrefix="UC" TagName="TestControl" Src="test.ascx" %>

You can also find related Interview Question to How to use a user control in a Web Forms page  below: 

How to create an instance of a user control programmatically in the code behind file of a Web Forms page

Create a new Web Forms page in Visual Studio.
Navigate to the code behind file generated for this Web Forms page.
In the Page_Load event of the Page class, write the following code.
// Load the control by calling LoadControl on the page class.
Control c1 = LoadControl("test.ascx");

// Add the loaded control in the page controls collection.


What is a user control?

An ASP.NET user control is a group of one or more server controls or static HTML elements that encapsulate a piece of functionality. A user control could simply be an extension of the functionality of an existing server control(s) (such as an image control that can be rotated or a calendar control that stores the date in a text box). Or, it could consist of several elements that work and interact together to get a job done (such as several controls grouped together that gather information about a user's previous work experience). (More...)

What is different between Web User Control and in Web Custom Control?

Web user controls : Web User Control is Easier to create and another thing is that its support is limited for users who use a visual design tool one gud thing is that its contains static layout one more thing a seprate copy is required for each application.

Web custom controls: Web Custom Control is typical to create and gud for dynamic layout and another thing is it have full tool support for user and a single copy of control is required because it is placed in Global Assembly cache. (More...)

How you will Hide Column(s) in the Windows Forms DataGridView Control?

Set the DataGridViewColumn.Visible property to false.

dataGridView1.Columns("CustomerID").Visible = False

dataGridView1.Columns["CustomerID"].Visible = False; (More...)

Is view state lost if a user refreshes a Web page? What if the user copies the URL and open it in other browser?

View state is maintained within a page's HTML, so it is lost if a page is refreshed or if the URL is copied. (More...)

What can you do to make a Web page more useful to a user who does not use a mouse?

There are number of things which can be done so that Site can be accessed without a mouse.

1.Provided access keys for all the controls.You can use access keys for Web controls using AccessKey property.
2. Define Logical Tab order.
3. Specify default button on the form.
4. Set default focus on the form in a logical location where data entry normally begins. (More...)

How do I host a WPF control in a Windows Forms application?

add references to the WPF namespaces (PresentationCore, PresentationFramework, UIAutomationProvider, UIAutomationTypes, and WindowsBase). Next create an instance of the ElementHost control and the control you wish to embed in the Windows Forms application and then hook that control up to the ElementHost control. Then simply add the ElementHost control to your Forms control collection:

ElementHost host = new ElementHost();

System.Windows.Controls.ListBox wpfListBox = new System.Windows.Controls.ListBox();

for (int i = 0; i < 10; i++)


wpfListBox.Items.Add("Item " + i.ToString());


host.Dock = DockStyle.Fill;



However, if you want to use XAML to describe the WPF control that you want to use in the Windows Forms application, you would need to add an Avalon UserControl item to your project. This will create a UserControl1.xaml file and a UserControl1.xaml.cs file. You can then modify the UserControl1.xaml file to contain whatever XAML you wish to describe your control. Then you would simply create an instance of this control and add it to the ElementHost control as in the above example:

ElementHost host = new ElementHost();

UserControl1 uc1 = new UserControl1();


host.Dock = DockStyle.Fill;


In addition, you will need to modify the project file because the Windows Application does not what to do with the XAML file. You will need to open the project file (.csproj, .vbproj, etc.) in an editor like Notepad and then scroll to the bottom. You will see the following line:

You will need to copy this line and paste it just below the above line and then change "CSharp" to "WinFX" so that the two lines look like:

Now save this file and reload the project using VS and run the application. (More...)

Difference Between User Control and Custom Control In Asp.Net?

User Controls: We need to implement with Predefined Functionality with Available Properties

Web User Controls:Web User Controls Implements Customized Properties and Customized Methods,we can develop any control with User defined Properties


How can we register a custom server control to a web page ?

we can register a custom server control to a web page using

@Register directive (More...)

How a user control is processed

When a page with a user control is requested, the following occurs:

1)The page parser parses the .ascx file specified in the Src attribute in the @ Register directive and generates a class that derives from the System.Web.UI.UserControl class.

2)The parser then dynamically compiles the class into an assembly.
If you are using Visual Studio, then at design time only, Visual Studio creates a code behind file for the user control, and the file is precompiled by the designer itself.

3)Finally, the class for the user control, which is generated through the process of dynamic code generation and compilation, includes the code for the code behind file (.ascx.cs) as well as the code written inside the .ascx file.

What are Events fired for User Control in ASP.NET ?

The Sequence of User controls Execution as follows.

OnInit of the user control
OnInit of the containing page
OnLoad of the containing page
OnLoad of the user control (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend