访问usercontrol中的usercontrol [英] access usercontrol inside usercontrol
本文介绍了访问usercontrol中的usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有这个问题
我在另一个用户控件中有一个用户控件。现在我想检索嵌套的用户控件控件值。我应该怎么做
我的用户控件是uc1并且它嵌套了uc2用户控件。
i想要获取具有uc1用户控件的ex.aspx页面中的uc2值。
请帮助
hello frens, i have this question
i have a user control inside another user control. now i want to retrieve that nested user controls control value. what should i do
my user control is uc1 and it has uc2 user control nested.
i want to get the uc2 value in ex.aspx page which has uc1 user control.
please help
推荐答案
不要。
这与在另一个表单打开的表单上访问数据相同 - 它将控件的设计锁定在一起并防止在考虑它们对外界影响的情况下进行更改。
相反,在外部控件中创建一个属性,返回所需的信息。它可以通过它的内部控制得到它,因为它的设计决定了 - 但外界不需要知道这个事实。
这使你的程序更清洁,
Don''t.
This is the same as accesing data on a form opened by another form - it locks the design of the controls together and prevents changes being made with considering their effect on the outside world.
Instead, create a property in the outer control, which returns the info you want. It can get it from it''s inner control or not as it''s design decides - but the outside world doe not need to be aware of the fact.
This makes your program both cleaner, and a lot more maintainable.
在你的第一个用户控件中,创建一个属性并解析第二个用户控件。
如:
Hi,
In your first user control, create a property and parse the second user control.
such as :
public class uc1 : UserControl
{
public UserControl uc2{get; set;}
//.....rest of your code here
}
public class uc2 : Usercontrol
{
//....
}
问候
Jegan
Regards
Jegan
这篇关于访问usercontrol中的usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文