System.Reflection SetProperty
This is my second post on using reflection. Here is the first. I started rewriting a web app which lists items then on selection shows the item summary (along with several item-specific functions) to support other similar item types. So it was an opportunity to implement a base class in the solution's WebUI project namespace and go from there. A method I wanted to use in the base class set a property in a control in the web project's .ASPX page. I've used reflection to get a property in a remote class web control, but never set a property. Here's how it works for me.
System.Web.UI.Control uc_doclist = Page.FindControl("uc_doclist");
Type ucType = uc_doclist.GetType();
System.Reflection.PropertyInfo prop = ucType.GetProperty("pid");
ucType.InvokeMember ("pid", BindingFlags.Default | BindingFlags.SetProperty,null,
uc_doclist, new object [] {int.Parse(e.CommandArgument.ToString())});
In my googling I found two reflection sources which were helpful: