How to create and use User Control in asp.net

Create an User Control
In this example I show that how easily we can create User Control and then use it in asp.net. Here first I create a User Control name CalendarUserControl.ascx, then place it Default.aspx web form. Here is the source code of both files.
CalendarUserControl.ascx

<%@ Control Language="C#" ClassName="CalendarUserControl" %>

<script runat="server">
    protected void Calendar1_SelectionChanged(object sender, System.EventArgs e) {
        Label1.Text = "Your selected Date is: " +
            Calendar1.SelectedDate.ToShortDateString();
    }
</script>
<h2>This is user control</h2>
<asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="DarkGreen"></asp:Label>
<br /><br />
<asp:Calendar ID="Calendar1" runat="server" BackColor="Beige" OnSelectionChanged="Calendar1_SelectionChanged">
</asp:Calendar>
Default.aspx

<%@ Page Language="C#" %>

<%@ Register src="CalendarUserControl.ascx" tagname="CalendarUserControl" tagprefix="uc1" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>User Control Example: how to create and use User Control in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1 style="color:Red;">This is page top</h1>
        <hr />
        <uc1:CalendarUserControl ID="CalendarUserControl1" runat="server" />
    
    </div>
    </form>
</body>
</html>
More asp.net examples