views:

23

answers:

2

how to set text property assigned to the control created dynamically usiong reflection?

Type type = Type.GetType(strFullName);

    object instance = Activator.CreateInstance(type);

    ctrlTemp = (Control)instance;

    ctrlTemp.ID = "Hello";
    ctrlTemp.Text???
    Panel1.Controls.Add(ctrlTemp);
+1  A: 

PropertyInfo.SetValue Method : Sets the value of the property with optional index values for index properties.

PropertyInfo piInstance = 
            typeof(Example).GetProperty("InstanceProperty");
        piInstance.SetValue(exam, 37, null);
Pranay Rana
A: 
if (ctrlTemp.GetType() == typeof(TextBox))
{
    TextBox textbox = (TextBox)ctrlTemp;
    ctrlTemp.Text = "Your text";
}
timothyclifford
+1 for Pranay :)
timothyclifford