すべてのカスタムコントロールによって実装されるインターフェイスを作成できます。このようにして、そのインターフェイスにキャストし、それを使用してデータを渡すことができます。この例を考えてみましょう。
public interface ICustomControl
{
string SomeProperty { get; set; }
}
...そしてあなたのコントロール:
public class Control1 : Control, ICustomControl
{
public string SomeProperty
{
get { return someControl.Text; }
set { someControl.Text = value; }
}
// ...
}
今、あなたはこのようなことをすることができます:
Control userControl = Page.LoadControl(control);
Page.Controls.Add(userControl);
if (userControl is ICustomControl)
{
ICustomControl customControl = userControl as ICustomControl;
customControl.SomeProperty = "Hello, world!";
}