ホスト ページから動的に読み込まれたユーザー コントロールのボタン クリック イベントを処理しようとしています。私の関連コードは以下に掲載されています。私は正しい道を進んでいると思いますが、この機能を適切に行うには他に何が必要ですか? 現在、「ターゲット メソッドへのバインディング エラー」というメッセージが表示されます。ユーザーコントロールを作成しようとすると。ご協力いただきありがとうございます。
aspx
<asp:UpdatePanel ID="upLeadComm" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:PlaceHolder ID="phComm" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
aspx.cs
else if (e.CommandName == "GetComm")
{
string[] cplArg = e.CommandArgument.ToString().Split('§');
UserControl ucLeadComm = (UserControl)LoadControl("Controls/Comments.ascx");
// Set the Usercontrol Type
Type ucType = ucLeadComm.GetType();
// Get access to the property
PropertyInfo ucPropLeadID = ucType.GetProperty("LeadID");
PropertyInfo ucPropLeadType = ucType.GetProperty("LeadType");
EventInfo ucEventInfo = ucType.GetEvent("BtnCommClick");
MethodInfo ucMethInfo = ucType.GetMethod("btnComm_Click");
Delegate handler = Delegate.CreateDelegate(ucEventInfo.EventHandlerType, ucType, ucMethInfo);
ucEventInfo.AddEventHandler(ucType, handler);
// Set the property
ucPropLeadID.SetValue(ucLeadComm, Convert.ToInt32(cplArg[0]), null);
ucPropLeadType.SetValue(ucLeadComm, cplArg[1], null);
phComm.Controls.Add(ucLeadComm);
upLeadComm.Update();
}
ascx.cs
public int LeadID { get; set; }
public string LeadType { get; set; }
public event EventHandler BtnCommClick;
public void btnComm_Click(object sender, EventArgs e)
{
BtnCommClick(sender, e);
}