【发布时间】:2017-08-03 16:38:51
【问题描述】:
我有可视 Web 部件和两个用户控件。
在可视化 Web 部件的 Page_Load() 上,我动态创建 userControl1:
protected void Page_Load(object sender, EventArgs e)
{
UserControl1 userControl = Page.LoadControl(userControl1Path) as UserControl1;
userControl.ID = "UserControl1";
this.Controls.Clear();
this.Controls.Add(userControl);
}
在 UserControl1 中,我有一个按钮,用于加载第二个用户控件 (UserControl2)(它可以工作!):
protected void GoToUserControl2_Click(object sender, EventArgs e)
{
UserContol2 userControl = Page.LoadControl(userControl2Path) as UserContol2;
userControl.ID = "UserContol2";
this.Controls.Clear();
this.Controls.Add(userControl);
}
UserControl2 也有一个按钮,但是当我单击它时 - 单击事件未触发。取而代之的是,单击按钮执行重定向到UserControl1。
即使按钮没有任何事件 - 它也会重定向到 UserControl1。
请帮帮我!
【问题讨论】:
-
在你的页面加载中设置一个断点,你会注意到 page_load 函数在每次回发时都会执行,我怀疑你的页面加载清除了控件 2 并使用了控件 1 的事件跨度>
标签: c# asp.net sharepoint user-controls web-parts