我正在尝试订阅用户控件的保存按钮事件,该事件是在来自调用父级的单独的radwindow中启动的。但我得到的对象没有初始化错误,我知道为什么但我错过了什么?
更新:我发现了我的错误,但似乎控件中的if(this.SaveEvent!= null)始终为null
家长控制代码:
public partial class myControl : ControlBase
{
private myChildControl __myChildControl;
private void myControl_PreRender(object sender, EventArgs e)
{
// error occurs here
//this.__myChildControl.SaveEvent += new myChildControl.SaveEventHandler(__myChildControl_SaveEvent);
// found my error
this.SaveEvent += new myChildControl.SaveEventHandler(__myChildControl_SaveEvent);
}
private void __myChildControl _SaveEvent(object sender, CustomEventArgs e)
{
this.Label1.Text = e.CustomEventArg1.ToString();
this.Label2.Text = e.CustomEventArg2.ToString();
}
}
RadWindow推出的儿童控制:
public partial class myChildControl : ControlBase
{
protected void btnSave_OnClick(object sender, EventArgs e)
{
CustomEventArgs _cea = new CustomEventArgs {CustomEventArg1 = 123, CustomEventArg2 = 12};
callBaseMethod(_cea);
}
}
ControlBase代码:
public class ControlBase : UserControl
{
public event CustomEventHandler SaveEvent;
public delegate void CustomEventHandler(object sender, CustomEventArgs e);
internal void callBaseMethod(CustomEventArgs cea)
{
if (this.SaveEvent!= null)
{
this.SaveEvent(this, cea);
}
}
}
CustomEventArgs类:
public class CustomEventArgs : EventArgs
{
public int CustomEventArgs1 { get; set; }
public int CustomEventArgs2 { get; set; }
}
答案 0 :(得分:1)
这在代码隐藏中是不可能的:RadWindow提供了一个单独的aspx / ascx页面,它通过javascript单独链接到主页面。
您需要做的是在javascript中处理RadWindow OnClientClose事件,然后在执行相应任务的父页面中触发一些内容。