Customise Pages using configuration in SQL Query
<p>I am using the following code to customise the UI of my pages. I have placed this code inside a base class which all pages inherit from. It works fine but can you help me make it a bit more generic and extendable? At the moment it only supports text boxes, buttons and labels for the controls and text or visible for the properties. I can of course add more controls and properties but I'd like to think there is a smarter way of doing this. The comments describe a bit of the code which is missing where the customisations are returned from a SQL query.</p>

<pre><code>    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            CustomisePage();
        }
    }

    protected void CustomisePage()
    {

        //Loops around SQL query results to get customisation values
        //for each loop iteration it populates controlName, propertyName, propertyValue and then calls.....

            Control controlToCustomise = FindControlRecursive(Page.Master, controlName);
            CustomiseControl(controlToCustomise, propertyName, propertyValue);
    }

    protected void CustomiseControl(Control controlToCustomise, string propertyNameToCustomise, string propertyValueToCustomise)
    {

        //Visible is common to all controls
        if (propertyNameToCustomise == "Visible")
        {
            controlToCustomise.Visible = bool.Parse(propertyValueToCustomise);
        }


        switch (controlToCustomise.GetType().ToString())
        {
            case "System.Web.UI.WebControls.Button":
                Button buttonToCustomise = controlToCustomise as Button;
                if (propertyNameToCustomise == "Text")
                {
                    buttonToCustomise.Text = propertyValueToCustomise;
                }
                break;
            case "System.Web.UI.WebControls.Label":
                Label labelToCustomise = controlToCustomise as Label;
                if (propertyNameToCustomise == "Text")
                {
                    labelToCustomise.Text = propertyValueToCustomise;
                }
                break;
            case "System.Web.UI.WebControls.TextBox":
                TextBox textBoxToCustomise = controlToCustomise as TextBox;
                if (propertyNameToCustomise == "Text")
                {
                    textBoxToCustomise.Text = propertyValueToCustomise;
                }
                break;
        }
    }

    protected Control FindControlRecursive(Control Root, string Id)
    {
        if (Root.ID == Id)
            return Root;

        foreach (Control Ctl in Root.Controls)
        {
            Control FoundCtl = FindControlRecursive(Ctl, Id);
            if (FoundCtl != null)
                return FoundCtl;
        }

        return null;
    }
</code></pre>
