日期:2014-05-18  浏览次数:20534 次

#################################有关从内容页引用母版页控件的问题
#####################################################################
master.aspx文件内容如下:
<%@   Master   Language= "C# "   AutoEventWireup= "true "   CodeFile= "MasterPage.master.cs "   Inherits= "MasterPage "   %>
<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title> 无标题页 </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
                <asp:contentplaceholder   id= "cphTest "   runat= "server ">
                    <asp:Label   ID= "lblMessage "   runat= "server "   Text= "Labelsecond "> </asp:Label>
                </asp:contentplaceholder>
        </form>
</body>
</html>
########################################################################
default.aspx文件内容如下:
<%@   Page   Language= "C# "   MasterPageFile= "~/MasterPage.master "   AutoEventWireup= "true "   CodeFile= "Default2.aspx.cs "   Inherits= "Default2 "   Title= "Untitled   Page "   %>
<%@   MasterType   VirtualPath= "~/MasterPage.master "   %>
<asp:Content   ID= "Content1 "   ContentPlaceHolderID= "cphTest "   Runat= "Server ">
</asp:Content>
#######################################################################
default.aspx.cs文件内容如下:
public   partial   class   Default2   :   System.Web.UI.Page
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
            ContentPlaceHolder   cph;
            Label   lblMe;
            cph   =   (ContentPlaceHolder)Master.FindControl( "cphTest ");
            if   (cph   !=   null)
            {
                Response.Write(cph.ID   +   " <br   /> ");
                lblMe   =   (Label)cph.FindControl( "lblMessage ");
                if   (lblMe   !=   null)
                    Response.Write(lblMe.ID);
                else
                    Response.Write( "Null ");
            }
        }
}
############################################################
疑问:为什么上面的代码输出Null?找不到lblMessage控件吗???
谢谢!!!

------解决方案--------------------
你要把 <asp:Label ID= "lblMessage " runat= "server " Text= "Labelsecond "> <