从子控件访问父控件 - ASP.NET C# [英] Accessing parent control from child control - ASP.NET C#
问题描述
我有一个标签的父用户控件。在父母的OnInit,我动态加载子控件。从孩子的控制,我将需要设置父的标签的东西。
I have a parent user control with a label. On the parent's OnInit, I dynamically load the child control. From the child control, I will need to set the parent's label to something.
使用Parent属性返回直接父,这实际上是在我的案件的占位符。从理论上讲,我可以递归循环来获取参考家长的用户控制。我在这里朝着正确的方向?是否有这样做的一个简单的方法是什么?
Using the Parent property returns the immediate parent which is actually a PlaceHolder in my case. Theoretically, I can recursively loop to get the reference to the Parent User control. Am I heading in the right direction here? Is there a straightforward way of doing this?
推荐答案
尝试让孩子的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.control.namingcontainer.aspx\">NamingContainer.
这篇关于从子控件访问父控件 - ASP.NET C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!