0
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Reference Control = "CHEADER.ascx" Page="~/Default.aspx" %>
<%@ Reference Control = "CLEFT_NAVIGATION.ascx" %>
<%@ Reference Control = "CCOPYRIGHT.ascx" %>
<%@ Reference Control = "CBOTTOM_NAVIGATION.ascx" %>

<%@ Reference Control = "CPAGE0001.ascx" %>
<%@ Reference Control = "CPAGE0002.ascx" %>
<%@ Reference Control = "CPAGE0003.ascx" %>



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>WELCOME</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

                <table align="center" style="width: 100%;">
                    <tr>
                        <td colspan="2">
                            <asp:PlaceHolder ID="HEADER" runat="server"></asp:PlaceHolder>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:PlaceHolder ID="LEFT_NAVIGATION" runat="server"></asp:PlaceHolder>
                        </td>
                        <td>
                            <asp:PlaceHolder ID="DETAILS" runat="server"></asp:PlaceHolder>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:PlaceHolder ID="COPYRIGHT" runat="server"></asp:PlaceHolder>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:PlaceHolder ID="BOTTOM_NAVIGATION" runat="server"></asp:PlaceHolder>
                            <uc1:WebUserControl ID="WebUserControl1" runat="server" />
                        </td>
                    </tr>
                </table>

            </ContentTemplate>
        </asp:UpdatePanel>

    </div>
    </form>
</body>
</html>

在后面的 .cs 代码上,我想使用以下代码

if(!Page.IsPostBack) { WebUserControl1 uc = (WebUserControl1) Page.LoadControl("WebUserControl1.ascx"); PlaceHolder1.Controls.Add(uc); }

- 但

如果我用名称 CHEADER 替换“WebUserControl1”,则没有出现任何用户控件,它说 CHEADER?那是什么!!

asp.net c# vsts2008

4

2 回答 2

1

尝试使用寄存器

<%@ Register Src="~/CHEADER.ascx" TagName="uc" TagPrefix="webcontrol" %>
于 2011-02-01T08:29:36.363 回答
0
protected void Page_Load(object sender, EventArgs e)
{

    Control details = LoadControl("WebUserControl.ascx");
    PlaceHolder1.Controls.Add(details);


    Control details1 = LoadControl("WebUserControl2.ascx");
    PlaceHolder2.Controls.Add(details1);



}

这有效:-)

于 2011-02-02T14:18:21.270 回答