---
title: "Difference between Server control and User control in asp.net"  
description: "In this blog I will talk about server control and user control in ASP.NET  User Control1.User control is a page file with extension .ascx which can on"  
author: "priyanka kushwaha"  
published: 2015-02-20  
updated: 2015-02-20  
canonical: https://www.mindstick.com/blog/780/difference-between-server-control-and-user-control-in-asp-dot-net  
category: ".net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Difference between Server control and User control in asp.net

In this blog I will talk about server control and [user control](https://www.mindstick.com/forum/294/problem-in-access-the-control-inside-the-user-control) in [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder)\

User Control

1. User control is a page file with [extension](https://www.mindstick.com/articles/22/extension-method) .ascx which can only be used within single application.

2. [User controls](https://www.mindstick.com/forum/343/logon-and-logoff-user-controls-how-to-set-isauthenticated-is-true) cannot be added to the toolbox of [visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available).NET. To use a user control with in an [aspx page](https://www.mindstick.com/forum/218/how-do-i-create-an-aspx-page-that-periodically-refreshes-itself) you have to drag the user control from the solution [explorer](https://www.mindstick.com/forum/34658/want-to-developed-windows-explorer-without-using-telerik) to designer Page.

3. User Controls can be viewed as a sort of generic controls during the design time. The proper GUI of user controls can be viewed only during the run time.

##### Server control

1. Custom controls are assemblies (.dll files) that can be used in [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) application.

2. It can be added to toolbox of VS.NET.

3. It can be viewed during the design time

##### Example:

User control:

Right click on solution Explorer>>Select Add option>>select New Item>>Web User control>>WebUserControl.ascx

```
 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl.ascx.cs" Inherits="UserComtrolSample.WebUserControl" %><table align="center">    <tr>        <td colspan="2">            <asp:Label ID="lblusername" runat="server" ForeColor="Red"></asp:Label>        </td>    </tr>    <tr>        <td>           EmailID :        </td>        <td>            <asp:TextBox ID="txtusername" runat="server"></asp:TextBox><asp:RequiredFieldValidator                ID="RequiredFieldValidator1" runat="server"                ControlToValidate="txtusername">*</asp:RequiredFieldValidator>            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtusername" runat="server" ErrorMessage="*" ForeColor="#339966" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>        </td>    </tr>    <tr>        <td>            &nbsp;        </td>        <td>            <asp:Button ID="btnSaveName" runat="server" Text="Save"             style="height: 26px" />        </td>    </tr></table>
```

Create a Default.[aspx file](https://www.mindstick.com/forum/108/is-it-possible-to-see-the-code-that-asp-dot-net-generates-from-an-aspx-file)

Drag a drop webusercontrol.ascx on Default.aspx file

```
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title></head><body>    <form id="form1" runat="server">        <uc1:WebUserControl runat="server" ID="WebUserControl" />    </form></body></html>
```

##### Example for Server control

Right click on solution Explorer>>Select Add option>>select New Item>>server control>>ServerControl.ascx

```
using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace CustomEmailControl.Controls{public class RequiredTextBox : TextBox    {        private RequiredFieldValidator _required;        private RegularExpressionValidator reqexp;        public string InvalidMessage;        public string RexInvalidMessage;        public string ClientScript = "true";        protected override void OnInit(EventArgs e)        {            _required = new RequiredFieldValidator();            _required.ControlToValidate = this.ID;            _required.ErrorMessage = this.InvalidMessage;            _required.EnableClientScript = (this.ClientScript.ToLower() != "false");            Controls.Add(_required);        }        protected override void Render(HtmlTextWriter w)        {             base.Render(w);            _required.RenderControl(w);         }    }}
```

Built solution explorer

Create a Default.aspx>>select toolbox>> add customControl.dll

```
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CustomEmailControl.Default" %><%@ Register Assembly="CustomEmailControl" Namespace="CustomEmailControl.Controls" TagPrefix="cc2" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title></head><body>    <form id="form1" runat="server">    <div>        <cc2:RequiredTextBox ID="RequiredTextBox1" InvalidMessage="Name is required."                          ClientScript="false" runat="server" RexInvalidMessage="Invalid Expression"></cc2:RequiredTextBox>        <asp:Button ID="Button1" runat="server" Text="Button" />    </div>    </form></body></html>
```

##### Output:

**![Difference between Server control and User control in asp.net](https://www.mindstick.com/blogs/3c0a6f3e-b17c-4c94-b100-04c325f7bc21/images/e8b340c7-9ba3-4457-9eae-6b7f011ed9d2.png)**

**![Difference between Server control and User control in asp.net](https://www.mindstick.com/blogs/3c0a6f3e-b17c-4c94-b100-04c325f7bc21/images/41c8fef2-7f18-443e-ae4f-ee67ce08682c.png)**

---

Original Source: https://www.mindstick.com/blog/780/difference-between-server-control-and-user-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
