Web用户控件之间传递值 [英] Passing Values between Web User Controls

查看:60
本文介绍了Web用户控件之间传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的asp.net页面上的多个Web用户控件,我想它们之间传递值。例如:

I've several web user controls on my asp.net page and I wanna pass values between them. For example :

有是在其中的一个,并当用户选择从DROPDOWNLIST任何项目,它可以通过选定值到其他用户控制,它包括的GridView从其中包含的dropdownlist用户控制显示所选项目值的相关数据的DROPDOWNLIST 。 (WOOW pretty蹩脚的句子寿)

There is a dropDownList in one of them and when user selects any item from dropDownList, it can pass the selected value to the other user control which includes GridView to show related data of selected item value from the user control which contains the dropdownlist. (woow pretty awkward sentence tho)

感谢和问候。

P.S:我们可以使用用户控件类的方式返回值

P.s : Can we use User controls as class in the way to return values ?

推荐答案

在DropDownList的onChange事件,那么你可以选择的项目值分配给其他用户控件的属性。

On the DropDownList onChange event you could then assign the selected item value to the property of the other user control.

好吧,你的用户控件应该有允许数据被设置属性。例如,在控制2你会:

Ok, your UserControls should have properties that allow data to be set. For example in Control2 you would have:

public string needData { 
get { return MyData; }
set { 
  MyData = value;
  //do whatever you need to do with that data here
}

现在在你的页面,你会捕捉到的DropDownList OnChange事件并在该你会是这样的:

Now in your page you would capture the DropDownList OnChange event and inside that you would something like this:

myControl2.needData = myDropDownList.SelectedValue;

这是否更有意义?

Does that make more sense?

这篇关于Web用户控件之间传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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