In this article we will learn how to use User Control in or why use user controls in or what is user controls in with example.


In software development, every developer or programmer wants to reusability of the code. In web form User Control provide reusability of code to the developer. For example we need to Login Form in many places in my application. In this situation we create a user control and use it everywhere, whenever we required.

Let’s see how to use user control:

In the previous article we created a User Control, and now we will try using it for the first time.  

Simply create a webfrom1.aspx and write the code inside webfrom1.aspx.

For now, let's just declare it within the page. Add the following line below the standard page declaration:

<%@ Register TagPrefix="UC" TagName="UserLoginControl" Src="_Login.ascx" %>

Make sure that the src value matches the path to your UserControl file. Now you may use the UserControl in your page, like any other control. For instance, like this:

<UC:UserLoginControl runat="server" ID="UserLoginControl" />

Full example of use user control in


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="TutorialsAsp.Net.WebForm1" %>
<%@ Register TagPrefix="UC" TagName="UserLoginControl" Src="_Login.ascx" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <title>Use User Controls</title>
    <form runat="server">
        <UC:UserLoginControl runat="server" ID="UserLoginControl" />

Now run your webform.aspx and see output like below:

how to use a UserControl in

I hope it will help to you after reading it.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like