Subscribing to an event of a ascx of another ascx in a different window

岁酱吖の 提交于 2019-12-11 23:50:45

问题


I'm trying to subscribe to the the save button event of a user control that is launched in a separate radwindow from the calling parent. but I am getting object not initialized error, I know why but what am I missing?

Update: I found my error but it appears that if (this.SaveEvent!= null) in the ControlBase is always null

Parent Control Code:

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();
    }
}

Child Control Launched in 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 Code:

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 class:

public class CustomEventArgs : EventArgs
{
    public int CustomEventArgs1 { get; set; }
    public int CustomEventArgs2 { get; set; }

}

回答1:


This isn't possible in codebehind: the RadWindow presents a separate aspx/ascx page altogether that is linked to the main page through javascript alone.

What you need to do is handle the RadWindow OnClientClose event in javascript, then fire something in the parent page that performs the appropriate tasks.



来源:https://stackoverflow.com/questions/8363215/subscribing-to-an-event-of-a-ascx-of-another-ascx-in-a-different-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!