从孩子共享价值于母公司控制 [英] Sharing value from child to parent control

查看:130
本文介绍了从孩子共享价值于母公司控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是比较新的这一点,但这里是我的问题。

I am relatively new to this, but here is my problem.

在asp.net,我有一个父和子控制。在子控件我有一个下拉列表。根据下拉列表中的选择的价值,我想切换面板的可见性在父母的控制。举例来说,如果我在子控件下拉列表中选择显示,我需要通过真正的母公司控制,使面板可见,反之亦然。我应该怎样做。我已阅读,可以通过事件处理完成,并且已经看到某些情况下,但我并不清楚这一点。请帮助!

In asp.net, I have a parent and a child control. Within the child control I have a dropdown list. Based on dropdown list's selected value I would like to toggle Visibility of Panel in parent control. For instance if I select Show in child control dropdown list, I need to pass true to parent control to make Panel visible and vice versa. How should I do that. I have read that can be done via the event handling and have seen certain scenarios but I am not clear on that. Please help!

感谢。

推荐答案

抬起你的父控件侦听事件。

Raise an event that your parent control listens for.

在背后为你的父母控制code,创建子控件的类型的对象。是这样的:

In the code behind for your parent control, create an object of the type of your child control. Something like:

private MyWebControl childControl;

然后在子控件,定义事件

Then in the child control, define an event

public event System.EventHandler SelectionChanged;

在你的DropDownList的OnIndexChanged事件后,你做你的处理,提高您的活动:

In the OnIndexChanged event of your DropDownList, after you do your processing, raise your event:

if(this.SelectionChanged!= null)
{
     this.SelectionChanged(this, new EventArgs()); 
     // You can send the index of the DDL in the event args
}

在您的父母控制,连接了该事件。 Page_Init好

In your parent control, wire up the event. Page_Init is good

this.childControl.SelectionChanged+=new EventHandler(childControl_SelectionChanged);

仍然在父控件,定义方法

Still in the parent control, define your method

private void childControl_SelectionChanged(object sender, EventArgs e)
{
      /// Do your processing here.
      /// Grab the DDL's index from the EventArgs and do your processing

}

应该是所有你需要得到它的工作!

Should be all you need to get it working!

这篇关于从孩子共享价值于母公司控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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