访问父用户控件中子用户控件的属性
我已在另一个静态后续代码中包含了一个用户控件:
将以下指令放在父页面的 asp 代码中或 用户控件:
<%@ Register src="Name_of_your_child_control.ascx" tagname="Name_of_your_child_control" tagprefix="uc1" %>
在父页面/控件的 asp 代码中使用以下标记:
..... 但问题是...我无法访问给定用户控件(父用户控件)中包含的用户控件的公共属性(子用户控件)...
请帮助:(
I have included a user control in another statically following code :
place the folowing directive in the asp code of the parent page or
usercontrol:
<%@ Register src="Name_of_your_child_control.ascx"
tagname="Name_of_your_child_control" tagprefix="uc1" %>
use the following tag in the asp-code of the parent page/control:
<uc1:Name_of_your_child_control ID="Name_of_your_child_control1"
runat="server" />
.....
But the issue is...i am not able to access the public properties of user control which got included(child user control) in given user control(parent user control)...
Please help :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设您的用户控件是这样的:
您的控件代码隐藏:
在包含该控件的父页面中,如下所示:
您可以在代码中使用该属性:
Say your usercontrol was this:
Your control code-behind:
In your parent page that included the control, like this:
You can use that property in code:
使用
必须适用于您的父用户控件。
Using
must work for your parent user control.
检查您正在使用的路径和文件名,Anish。你有问题。 Visual Studio 是否告诉您它找不到控件?是不是编译时就失败了?运行时?
Check the path and file names you are using, Anish. You have something wrong. Is Visual Studio telling you it can't find the control? Is it failing at compile time? Runtime?
这很有趣,但是每当您向用户控件添加属性时。
您需要在父级中再次注册它。因此,在您的情况下,
在此行末尾添加一个空格并再次将其删除:
$<% Register src="~/MyControl.ascx" tagname="MyControl" tagprefix="uc1" %>
这将重新注册用户控件,您将能够访问新的特性。
It's funny but whenever you add a property to a user control.
You need to register it again in the parent. So in your case,
Add a space at the end of this line and remove it again:
$<% Register src="~/MyControl.ascx" tagname="MyControl" tagprefix="uc1" %>
This will re - register the user control and you will be able to access new properties.