Dynamically cast a control type in runtime
<p>I have an application whereby I dynamically create controls on a form from a database.
This works well, but my problem is the following:</p>

<pre><code>    private Type activeControlType;        

    private void addControl(ContainerControl inputControl, string ControlName, string Namespace,
        string ControlDisplayText, DataRow drow, string cntrlName)
    {
        Assembly assem;
        Type myType = Type.GetType(ControlName + ", " + Namespace);
        assem = Assembly.GetAssembly(myType);

        Type controlType = assem.GetType(ControlName);
        object obj = Activator.CreateInstance(controlType);
        Control tb = (Control)obj;
        tb.Click += new EventHandler(Cntrl_Click);
        inputControl.Controls.Add(tb);
        activeControlType = controlType;
    }

    private void Cntrl_Click(object sender, EventArgs e)
    {
         string test = ((activeControlType)sender).Text;  //Problem ???
    }
</code></pre>

<p>How do I dynamically cast the sender object to a class that I can reference the property fields of it.</p>

<p>I have googled, and found myself trying everything I have come across..... Now I am extremely confused... and in need of some help</p>

<p>Thnx</p>

<p>JT</p>
