订阅另一ASCX的ASCX的事件在不同的窗口 [英] Subscribing to an event of a ascx of another ascx in a different window

查看:138
本文介绍了订阅另一ASCX的ASCX的事件在不同的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想订阅到在从调用父单独radwindow推出了用户控件的保存按钮事件。但我越来越没有初始化对象错误,我知道为什么,但我缺少什么?

更新:我发现我的错误,但它看来,如果(this.SaveEvent!= NULL)在ControlBase总是空

家长控制code:

 公共部分类myControl:ControlBase
{
    私人myChildControl __myChildControl;    私人无效myControl_ preRender(对象发件人,EventArgs的发送)
    {
        //此处出现错误
        //this.__myChildControl.SaveEvent + =新myChildControl.SaveEventHandler(__ myChildControl_SaveEvent);
        //发现我的错误
        this.SaveEvent + =新myChildControl.SaveEventHandler(__ myChildControl_SaveEvent);
    }    私人无效__myChildControl _SaveEvent(对象发件人,CustomEventArgs E)
    {
         this.Label1.Text = e.CustomEventArg1.ToString();
         this.Label2.Text = e.CustomEventArg2.ToString();
    }
}

在RadWindow启动子控制:

 公共部分类myChildControl:ControlBase
{
    保护无效btnSave_OnClick(对象发件人,EventArgs的发送)
    {
        CustomEventArgs _cea =新CustomEventArgs {CustomEventArg1 = 123,CustomEventArg2 = 12};
        callBaseMethod(_cea);
    }
}

ControlBase code:

 公共类ControlBase:用户控件
{
    公共事件CustomEventHandler SaveEvent;
    公共委托无效CustomEventHandler(对象发件人,CustomEventArgs E);    内部空隙callBaseMethod(CustomEventArgs CEA)
    {
        如果(this.SaveEvent!= NULL)
        {
            this.SaveEvent(这一点,CEA);
        }
    }
}

CustomEventArgs类:

 公共类CustomEventArgs:EventArgs的
{
    公众诠释CustomEventArgs1 {搞定;组; }
    公众诠释CustomEventArgs2 {搞定;组; }}


解决方案

这是不是在codebehind可能:在RadWindow $ P $完全是通过JavaScript链接到主网页psents一个独立的ASPX / ASCX页面单独。

您需要做的是处理JavaScript中的RadWindow OnClientClose事件是什么,然后火在执行相应的任务父页面的东西。

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

}

解决方案

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.

这篇关于订阅另一ASCX的ASCX的事件在不同的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆