我有一个父用户控件,我在其中注册了一个子用户控件。我想访问我从母版页继承的 aspx 页面中的子用户控件中存在的控件。
下面是我的代码:
//Parent UserControl
public partial class WebUserControlParent : System.Web.UI.UserControl
{
public WebUserControlChild checkbox
{
get
{
return this.checkbox;
}
}
public WebUserControlChild label
{
set
{
this.label = value;
}
get
{
return this.label;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
//Child User Control :
public partial class WebUserControlChild : System.Web.UI.UserControl
{
public bool Checked
{
set
{
this.checkboxchild.Checked = value;
}
}
public string Text
{
set
{
this.labelchild.Text = "YooHoo!";
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
//My Aspx Page:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.PageControl.checkbox.Checked = true;
this.PageControl.label.Text = "YoooHooo!";
}
}
//My Parent usercontrol .ascx stuff
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControlParent.ascx.cs"
Inherits="WebApplication2.WebUserControlParent" %>
<%@ Register Src="~/WebUserControlChild.ascx" TagName="Child" TagPrefix="cc" %>
//My Child Usercontrol Stuff
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControlChild.ascx.cs"
Inherits="WebApplication2.WebUserControlChild" %>
<asp:CheckBox ID="checkboxchild" runat="server" Checked="false" />
<asp:Label ID="labelchild" runat="server"></asp:Label>
//My ASPX Page Stuff
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<%@ Register Src="~/WebUserControlParent.ascx" TagName="Control" TagPrefix="cc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<cc:Control ID="PageControl" runat="server" />
</asp:Content>
当我这样做时,我的代码说线程对一些代码感到兴奋......任何人都可以建议我我做错了什么以及应该是什么解决方案......谢谢