订阅不同窗口中另一个ascx的ascx的事件



我试图订阅用户控件的保存按钮事件,该事件在调用父控件的单独radwindow中启动。但我得到对象未初始化错误,我知道为什么,但我错过了什么?

更新:我发现我的错误,但似乎如果(this.SaveEvent!= null)在ControlBase中总是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; }
}

这在代码隐藏中是不可能的:RadWindow呈现了一个单独的aspx/ascx页面,它单独通过javascript链接到主页面。

你需要做的是在javascript中处理RadWindow OnClientClose事件,然后在父页面中触发一些执行适当任务的东西。

相关内容

  • 没有找到相关文章

最新更新