In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls called User Controls. You can also convert any page existing .aspx page into a user control. In this quick tutorial, I have explained that how you can convert an .aspx page into a user control.

Step 1:-

Create a new website in Visual Studio 2008 and name it whatever you want.


Step 2:-

For just a demo, insert label (or any other control if you want).


Step 3:-

Now rename the page from .aspx extension to .ascx extension. Then remove html, head, body and form tags from the page and remove all attributes of the "@ Control" directive apart from Language, AutoEventWireup, CodeFile, and Inherits.

Step 4:-

Change the “@Page” directive to “@Control”. Now we also need to rename the code file that is default.aspx.cs but you can’t rename it when Visual Studio is running. So you have to close Visual studio and then rename Default.aspx.cs to Default.ascx.cs.

After all this, your .aspx page should look like the image below.


This page is your user control and you can use it in any .aspx page as a user control …you just have to drag/drop it from solution explorer.