Custom Controls ASP.Net Tutorial

File: Control.ascx
<%@ Control Language="C#" ClassName="AddressForm" %>

    public string Title
    {
        get { return ltlTitle.Text; }
        set { ltlTitle.Text = value; }
    }
    public string Street
    {
        get { return txtStreet.Text; }
        set { txtStreet.Text = value; }
    }
    public string City
    {
        get { return txtCity.Text; }
        set { txtCity.Text = value; }
    }
    public string State
    {
        get { return txtState.Text; }
        set { txtState.Text = value; }
    }
    public string PostalCode
    {
        get { return txtPostalCode.Text; }
        set { txtPostalCode.Text = value; }
    }



            ID="ltlTitle"
        Text="Address Form"
        runat="server" />


    ID="lblStreet"
    Text="Street:"
    AssociatedControlID="txtStreet"
    Runat="server" />


    ID="txtStreet"
    Runat="server" />
    ID="reqStreet"
    Text="(required)"
    ControlToValidate="txtStreet"
    Runat="server" />



    ID="lblCity"
    Text="City:"
    AssociatedControlID="txtCity"
    Runat="server" />


    ID="txtCity"
    Runat="server" />
    ID="reqCity"
    Text="(required)"
    ControlToValidate="txtCity"
    Runat="server" />



    ID="lblState"
    Text="State:"
    AssociatedControlID="txtState"
    Runat="server" />


    ID="txtState"
    Runat="server" />
    ID="reqState"
    Text="(required)"
    ControlToValidate="txtState"
    Runat="server" />



    ID="lblPostalCode"
    Text="Postal Code:"
    AssociatedControlID="txtPostalCode"
    Runat="server" />


    ID="txtPostalCode"
    Runat="server" />
    ID="RequiredFieldValidator1"
    Text="(required)"
    ControlToValidate="txtPostalCode"
    Runat="server" />



File: Default.aspx
<%@ Page Language="C#" %>
<%@ Register TagPrefix="user" TagName="AddressForm" Src="~/Control.ascx" %>
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ltlResults.Text = "Billing Street: " + AddressForm1.Street;
        ltlResults.Text += "Billing City: " + AddressForm1.City;
        ltlResults.Text += "Billing State: " + AddressForm1.State;
        ltlResults.Text += "Billing Postal Code: " + AddressForm1.PostalCode;
        ltlResults.Text += "";
        ltlResults.Text += "Shipping Street: " + AddressForm2.Street;
        ltlResults.Text += "Shipping City: " + AddressForm2.City;
        ltlResults.Text += "Shipping State: " + AddressForm2.State;
        ltlResults.Text += "Shipping Postal Code: " + AddressForm2.PostalCode;
    }



    
        html
        {
            background-color:silver;
            font:14px Georgia,Serif;
        }
        .content
        {
            background-color:white;
            width:600px;
            margin:auto;
            padding:20px;
        }
        .addressLabel
        {
            float:left;
            width:100px;
            padding:5px;
            text-align:right;
        }
        .addressField
        {
            float:left;
            padding:5px;
        }
        .clear
        {
            clear:both;
        }
    
    Checkout


    
    
            id="AddressForm1"
        Title="Billing Address"
        Runat="server" />
    
            id="AddressForm2"
        Title="Shipping Address"
        Runat="server" />
    
            ID="btnSubmit"
        Text="Submit Form"
        OnClick="btnSubmit_Click"
        Runat="server" />
    
            id="ltlResults"
        Runat="server" />