あなたがで実装されたインタフェースを作成することができますすべてのカスタムコントロール。この方法で、そのインターフェイスにキャストし、それを使ってデータを渡すことができます。この例を考えてみましょう:
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!";
}
完璧! :) どうも –