protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label lab = new Label();
lab.ID = "lab1";
lab.Text = "11111";
Panel1.Controls.Add(lab);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = ((TextBox)(Panel1.FindControl("lab1"))).Text;//未将对象引用到实例
}
{
if (!IsPostBack)
{
Label lab = new Label();
lab.ID = "lab1";
lab.Text = "11111";
Panel1.Controls.Add(lab);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = ((TextBox)(Panel1.FindControl("lab1"))).Text;//未将对象引用到实例
}
{
Label lab = new Label();
lab.ID = "lab1";
lab.Text = "11111";
Panel1.Controls.Add(lab);
}
protected void Button1_Click(object sender, EventArgs e)
{ TextBox1.Text = ((Label)Panel1.FindControl("lab1")).Text;//未将对象引用到实例
}
可是就是获取不到它的值。
{
Label lab = new Label();
lab.ID = "lab1";
lab.Text = "11111";
Panel1.Controls.Add(lab);
TextBox1.Text = lab.Text;
}
你用我的嗲吗测试下呢
前台
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
</asp:Panel>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
后台
protected void Page_Load(object sender, EventArgs e)
{
Label lab = new Label();
lab.ID = "lab1";
lab.Text = "11111";
Panel1.Controls.Add(lab);
}
protected void Button1_Click(object sender, EventArgs e)
{ TextBox1.Text = ((Label)Panel1.FindControl("lab1")).Text;//未将对象引用到实例
}
没有理解
Page.ISPostBack()的用法