子级用户控件不会触发其已注册的事件
所以这里是我的控件布局,我已经删除了表格的格式以及不是。我遇到的问题是事件InterventionSaved
始终为空。子级用户控件不会触发其已注册的事件
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="rptAreaConcern_ItemDataBound">
<ItemTemplate>
<asp:UpdatePanel ID="updIntervenion" runat="server">
<ContentTemplate>
<UC:InterventionLayout ID="InterventionLayout" runat="server"/>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
在页面代码后面我试图注册事件InterventionLayout.InterventionSaved
在repeater1
每个项目。
protected void rptAreaConcern_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
InterventionLayout InterventionLayout = ((InterventionLayout)e.Item.FindControl("InterventionLayout"));
//InterventionLayout.ProgressMonitor = ddlProgressMonitoringOwner; //tried to pass the drop
//InterventionLayout.ProgressMonitorDuration = ddlDuration; //down lists to the control(fail)
InterventionLayout.InterventionSaved += new EventHandler(NonAcademicInterventionSaved);
InterventionLayout.LoadAssignedInterventionData();
}
private void NonAcademicInterventionSaved(object sender, EventArgs e)
{
//this never gets called
//ParentSave();
//UpdatePanel();
}
现在,在我的用户InterventionLayout.ascx.cs
我有我已经偶数定义保存按钮调用Save_Clicked(object sender, EventArgs e)
为:
public event EventHandler InterventionSaved;
protected void btnSave_Click(object sender, EventArgs e)
{
Save();
if(null != InterventionSaved) // this is always null
InterventionSaved(this, new EventArgs());
}
InterventionSaved总是空。我不知道为什么或者如果我做错了什么。当我步入InterventionLayout.LoadAssignedInterventionData()
时,我知道它在控制中。然后当我把我的中断点设置为btnSave_Click
时InterventionSaved
始终为空。
我的主要目标是能够通知父母并运行其NonAcademicInterventionSaved()
方法。从那里我想最终导致updatepanel刷新。我所要做的不应该很复杂,但它会比预期的更令人头疼。
找到了答案: button event in nested repeater
确保其在onItemCreated
@ user655810添加:但这正是你的情况。一个嵌套的中继器中的用户控件,相信我,它的工作原理;)你在哪里添加处理程序?您必须将其添加到嵌套中继器的ItemCreated中(如我的示例中所示),而不是ItemDataBound(每次回发时针对ItemDataBound调用ItemCreated)。 - Tim Schmelter 3月18日16:23
您可能需要在回发后重建InterventionLayouts的中继器集合,以便ASP.NET可以匹配事件。
如果问题是repeater或UpdatePanel中的controll,我不是100%舒尔。如果你删除的UpdatePanel是NonAcademicInterventionSaved被解雇? – 2011-04-06 12:24:54