comment ajouter des contrôles à la masterpage du contenu de l'espace réservé par programmation

Sur la base.maître:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Base.master.cs" Inherits="WebApplicationControlTest.Base" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>The title</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        There is a content here: <br />
        <asp:ContentPlaceHolder ID="body" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

Sur le imbriquée maître

<%@ Master Language="C#" MasterPageFile="~/MasterPages/Base.Master" AutoEventWireup="true" CodeBehind="NestedMasterPageTest2.master.cs" Inherits="WebApplicationControlTest.MasterPages.NestedMasterPageTest2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="PlaceHolder" ContentPlaceHolderID="body" runat="server">
    This is inside the NestedPage<br />
    <asp:ContentPlaceHolder ID="PlaceHolderLeft" runat="server">
    </asp:ContentPlaceHolder>
    <asp:ContentPlaceHolder ID="PlaceHolderRight" runat="server">
    </asp:ContentPlaceHolder>
</asp:Content>

et sur la valeur par défaut.aspx

<asp:Content ID="PlaceHolder" ContentPlaceHolderID="PlaceHolderLeft" runat="server">
    This is a test!
</asp:Content>

sur la valeur par défaut.aspx.cs

protected override void OnPreInit(EventArgs e){
    Control control = LoadControl("TheUrlOfTheControl.ascx");
    if (Page.Master.FindControl("body") != null) {
        Page.Master.FindControl("body").Controls.Add(control);
    }
}

J'ai besoin d'ajouter le contrôle à la dernière partie du contenu du corps de l'espace Réservé mais FindControl retourne null... comment peut-on ajouter des contrôles à la masterpage du contenu de l'espace réservé par programmation?

Grâce

InformationsquelleAutor Jronny | 2009-12-15