我正在在.netC#如何獲得overrided面板的用戶控制
我已經覆蓋了Panel控件,使一個div點擊一個C#Web應用程序內工作。它看起來像這樣:
public class ProjectPanel : System.Web.UI.WebControls.Panel, System.Web.UI.IPostBackEventHandler
{
public ProjectPanel()
{
CssClass = "project";
this.Click += new EventHandler(ProjectPanel_Click);
}
public event EventHandler Click;
protected virtual void OnClick(EventArgs e)
{
if (Click != null)
{
Click(this, e);
}
}
public void RaisePostBackEvent(string eventArgument)
{
OnClick(new EventArgs());
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
this.Attributes.Add("onclick", "__doPostBack('" + this.ClientID + "', '');");
base.Render(writer);
}
public void ProjectPanel_Click(object sender, EventArgs e)
{
Label l = new Label();
l.Text = " HIYA";
this.Controls.Add(l);
}
}
現在,這可以在頁面內正常工作。不過,我也有一個Web用戶控件,它看起來像:
<div class="team">
<asp:Panel runat="server" ID="TheCanvas" CssClass="projects" />
</div>
現在,當我添加了被覆蓋的面板到TheCanvas面板,單擊事件心不是註冊了。回發發生,但ProjectPanel_Click不會觸發。有任何想法嗎?我通過代碼添加面板。