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);
        }      
    }

posted on 2008-09-29 12:00  朱胜  阅读(259)  评论(0编辑  收藏  举报