Access child user control#39;s property in parent user control(在父用户控件中访问子用户控件的属性)
问题描述
我在另一个静态代码中包含了一个用户控件:
I have included a user control in another statically following code :
将以下指令放在父页面的 asp 代码中或用户控制:
place the folowing directive in the asp code of the parent page or usercontrol:
<%@ 注册 src="TmFtZV9vZl95b3VyX2NoaWxkX2NvbnRyb2wuYXNjeA=="tagname="Name_of_your_child_control" tagprefix="uc1" %>
在父页面/控件的asp-code中使用以下标签:
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)...
请帮忙:(
推荐答案
假设你的用户控件是这样的:
Say your usercontrol was this:
<%@ Control Inherits="Project.MyControl" Codebehind="MyControl.ascx.cs" %>
<asp:TextBox ID="TB" runat="server" />
您的控制代码隐藏:
namespace Project
{
public partial class MyControl : UserControl
{
public string MyTextProperty
{
get { return TB.Text; }
set { TB.Text = value; }
}
}
}
在包含控件的父页面中,如下所示:
In your parent page that included the control, like this:
<%@ Register src="fi9NeUNvbnRyb2wuYXNjeA==" tagname="MyControl" tagprefix="uc1" %>
<uc1:MyControl ID="MyControlID" runat="server" />
您可以在代码中使用该属性:
You can use that property in code:
MyControlID.MyTextProperty = "bob";
这篇关于在父用户控件中访问子用户控件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在父用户控件中访问子用户控件的属性


- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01