J'ai un contrôle utilisateur parent dans lequel j'ai enregistré un UserControl. Je veux accéder aux contrôles présents dans le contrôle utilisateur enfant dans ma page aspx dont j'ai hérité d'une page maître.Récupère les contrôles imbriqués dans asp.net
Ci-dessous mon code:
//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>
Quand je fais cela, mon code dit enfilez excité avec un code ... Quelqu'un peut-il me suggérer ce que i`m faire le mal et ce qui devrait être la solution pour cette .. Merci