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="Name_of_your_child_control.ascx"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="~/MyControl.ascx" tagname="MyControl" tagprefix="uc1" %>
<uc1:MyControl ID="MyControlID" runat="server" />
您可以在代码中使用该属性:
You can use that property in code:
MyControlID.MyTextProperty = "bob";
这篇关于在父用户控件中访问子用户控件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在父用户控件中访问子用户控件的属性


基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01