復制代碼 代碼如下:
Panel spnButtons = new Panel();
Button btn = new Button();
btn.ID = "btn1";
spnButtons.Controls.Add(btn);
// 輸出True,表示沒有找到控件
Response.Write(spnButtons.FindControl(btn.ID) == null);
復制代碼 代碼如下:
Panel spnButtons = new Panel();
Page.Controls.Add(spnButtons);// 創建Panel后把它加入Page
Button btn = new Button();
btn.ID = "btn1";
spnButtons.Controls.Add(btn);
// 輸出False,表示找到了控件
Response.Write(spnButtons.FindControl(btn.ID) == null);
復制代碼 代碼如下:
Repeater spnButtons = new Repeater();
Button btn = new Button();
btn.ID = "btn1";
spnButtons.Controls.Add(btn);
// 輸出False,表示找到了控件
Response.Write(spnButtons.FindControl(btn.ID) == null);
復制代碼 代碼如下:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
myPanel spnButtons = new myPanel();
Button btn = new Button();
btn.ID = "btn1";
spnButtons.Controls.Add(btn);
Response.Write(spnButtons.FindControl(btn.ID) == null);
}
}
public class myPanel : Panel, INamingContainer
{
public myPanel():base()
{
}
}
新聞熱點
疑難解答
圖片精選