孩子的访问用户控件的父用户控件属性 [英] Access child user control's property in parent user control

查看:90
本文介绍了孩子的访问用户控件的父用户控件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经包含在另一个静态下code用户控件:

I have included a user control in another statically following code :

将如下因素指令在父页面的ASP code或
用户控件:

place the folowing directive in the asp code of the parent page or usercontrol:

<%@注册SRC =Name_of_your_child_control.ascx
标记名=Name_of_your_child_control标签preFIX =UC1%GT;

使用下面的标记在父页/控制的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
=服务器/>

.....
但问题是......我不能够访问用户控制哪些得到了包括在给定的用户控件的公共属性(子用户控件)(父用户控件)...

..... 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" />

您控制code-背后:

Your control code-behind:

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" />

您可以使用该属性在code:

You can use that property in code:

MyControlID.MyTextProperty = "bob";

这篇关于孩子的访问用户控件的父用户控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆