Easily Absorb Multiple Web Controls Via NameSpace Reference

Instead of having multiple references to separate controls in your pages. You can put all of them under 1 namespace and reference the single NameSpace. This will allow all controls under this namespace to be accessible.

Create the control by adding a new class into the App_Code directory. In the class definition make sure it inherits CompositeControl.

State Web Control DropDown Field

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using AppName.Objects;

/// <summary>
/// Summary description for StateDropDown
/// </summary>

namespace AppName.WebControls.Fields
    public class StateDropDown : CompositeControl

        public StateDropDown() { }

        // Private Properties
        #region Private Properties
        // Controls   
        private DropDownList _DropDownList = new DropDownList();
        private LiteralControl _LitExample = new LiteralControl();

        // Internal Properties (formerly stored in ViewState)
        private bool _IsExampleVisible = true; // Example is visible by default
        private bool _IsRequired = false;
        private string _OverrideExample = "";
        private State.StateType _StateType = State.StateType.All; // Show all states by default
        private string _ValidationGroup = "";

To use this new control or any control under this namespace simply reference the NameSpace directly within your ASPX.

<%@ Page Language="C#" Theme="LightTheme" %>
<%@ Register TagPrefix="fields" Namespace="AppName.WebControls.Fields" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="AppName.Objects" %>

<script runat="server">
    // Protected Properties   
    protected enum PageStateName

<div class="field">                         
     <fields:StateDropDown ID="DdlState" runat="server" IsRequired="false"></fields:StateDropDown>


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s