I have a set of user controls on a page that are dynamically loaded based on condition to run a variety reports (the condition driver). Each control has one or more properties exposed that will be used to get data from my database query. Because the controls vary for each report I wrote a procedure to access the appropriate control’s property by name so I can send it to the database query in the code behind (C#). I got it all setup to access the public property like this:
stringVal = userControl.Attributes[stringName].ToString();
and it is telling me that I need to new up an object. I don’t understand how I need to access that property dynamically by string name. In my immediate window I can see the property I want; but, it is not an “Attribute” as control.Attributes.Count = 0. So, how do I need to set this up properly so I can access it by string name? Do I need to decorate the property with something?
Thank you in advance.
Below, I’ve written a wrapper class you can use to set/get public fields or properties of the wrapped class by string name.
First, let’s look at how you could use it on a class that had the public fields or properties StartDate and SocialSecurityNumber.
And now on to how it’s implemented: