模板页:<asp:Label ID="LabDemo" runat="server" text="Test" />
内容页:
Label lb = (Label)Master.FindControl("LabDemo");//直接在模板页中找LabDemo
if (lb != null)
{
Response.Write("<script>alert('" + lb.Text.ToString() + "')</script>");
}
另外一种情况,当控件在Master中的ContentPlaceHolder里的话则需要:
ContentPlaceHolder a = (ContentPlaceHolder)Master.FindControl("Content2");//先找到ContentPlaceHolder的ID
if(a!= null)
{
`TextBox Txt=(TextBox)a.FindControl("TxtDemo");
if(Txt != null)
{
Response.write(Txt.text.ToString());
}
}