Page.PraseControl方法后台动态生成前台控件方法:
protected void Page_Load(object sender, EventArgs e)
{
//添加控件
Control myControl = Page.ParseControl("<table cellspacing='1' cellpadding='1' width='100%' border='1' style='font-size:9pt'> <tr> <td> <asp:TextBox ID='TextBox1' runat='server' Text='sdfa'> </asp:TextBox> </td> </tr> </table>");
this.form1.Controls.Add(myControl);
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.Page.FindControl("TextBox1") != null)
{
//获取控件中的值
TextBox tb = (TextBox)this.Page.FindControl("TextBox1");
Response.Write(tb.Text);
}
}
本文介绍如何在ASP.NET中使用Page.ParseControl方法动态生成前台控件,通过示例代码展示了如何添加一个包含TextBox的table控件,并在按钮点击事件中获取该TextBox的值。

2792

被折叠的 条评论
为什么被折叠?



