Reputation: 4981
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);
Upvotes: 0
Views: 176
Reputation: 6969
if (ctrlTemp.GetType() == typeof(TextBox))
{
TextBox textbox = (TextBox)ctrlTemp;
ctrlTemp.Text = "Your text";
}
Upvotes: 0
Reputation: 176936
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);
Upvotes: 1