【发布时间】:2010-02-19 07:00:57
【问题描述】:
我有自己的 Control1,它作为子控件动态添加到 Control2,它在 control2 的 CreateChildControls() 中实现 INamingContainer。
Control1 本身实现 IPostBackEventHandler。但是,尽管我确实从 JavaScript 调用了回发方法,但从未在 Control1 上调用 RaisePostBackEvent() 方法。
是的,页面上还有其他实现 IPostBackEventHandler 接口的控件。
我错过了什么?
什么可能导致问题?
更新:Control1 始终以完全相同的方式创建并在 Control2 中分配完全相同的 ID
在 Control2 中看起来像这样:
protected override void CreateChildControls()
{
if(!this.DesignMode)
{
Control1 c = new Control1();
c.ID = "FIXED_ID";
}
base.CreateChildControls();
}
更新2: 控制1:
public class Control1: Control, IPostBackEventHandler
{
...
protected virtual void RaisePostBackEvent(string eventArgument)
{
if(!String.IsNullOrEmpty(eventArgument))
{
// Some other code
}
}
}
如果我添加行
Page.RegisterRequiresRaiseEvent(c);
在 Control2 中的 CreateChildControls() 中调用此方法,但始终使用 null eventArgument。
更新3:
在某些 onClick 事件的 JavaScript 中,我执行以下操作:
__doPostBack(Control1.UniqueID,'commandId=MyCommand');
其中 Control1.UniqueID 在渲染过程中当然会替换为真实的 uniqueID。我查了一下,这个脚本正在被调用。
【问题讨论】:
-
@Artem,请说明您是如何注册回发脚本的?这是您的控件的一般结构。
标签: asp.net asp.net-ajax postback custom-controls