从所有用户控件扩展的基本用户控件访问页面属性
本文关键字:控件 用户 访问 属性 扩展 | 更新日期: 2023-09-27 17:54:41
我有一个页面,里面有几个web用户控件
Page执行以下操作,它扩展了Icode接口
public partial class TestPage: System.Web.UI.Page, ICode
//它在这里实现了代码实现
public string Code
{
get
{
return "sample code";
}
}
其中一个控件如下
我可以从这个示例控件
访问Code值sampleControl:BaseControl
// here I am able to access the page property's
if (Page is ICode)
{
string test= ((ICode))Page).Code;
}
现在我想从BaseControl访问相同的值,因为BaseControl在页面之前执行我无法在基本控件中设置值。
BaseControl: System.Web.UI.UserControl
{
// how can i access those values here.
}
如果我可以在基本控件中设置值,那么所有控件都可以访问该值
如有任何帮助,不胜感激
听起来你的依赖链颠倒了。控件应该是一个可重用的单元,而页面应该包含控件。您不应该尝试从控件中访问页面级属性,而应该从页面中设置控件的属性。