I would like to set the a property value on a user control. It sounds easy enough. First, I would like to create a web control then I would like to access one of its properties "HasAccess" and set the value to "true".
In this example we are assuming that the web control is been called from a master page and the property that needs to be set is from a web page. In the web page we need to first find the user control and then set its property.
if (Master != null)
{
Control ctlMyControl = Master.FindControl("ctlMyControl")
as Control;
if (ctlMyControl != null)
{
Type ucType = null;
ucType = ctlMyControl .GetType();
PropertyInfo hasAccess = ucType.GetProperty("HasAccess");
// Only set the first control as each on page
// will pass through code.
if (hasAccess.GetValue(ctlMyControl , null) == null)
hasAccess.SetValue(ctlMyControl , True, null);
}
}