我问一下
怎么给动态产生的控件加runat属性啊?

解决方案 »

  1.   


     protected void Page_Load(object sender, EventArgs e)
            {
                HtmlTable htmlTable = new HtmlTable();
                htmlTable.ID = "HtmlTable1";            HtmlTableCell htmlTableCell = new HtmlTableCell();
                htmlTableCell.InnerHtml = "Name";
                HtmlTableRow htmlTableRow1 = new HtmlTableRow();
                htmlTableRow1.Cells.Add(htmlTableCell);
                htmlTable.Rows.Add(htmlTableRow1); 
                HtmlTableRow htmlTableRow2= new HtmlTableRow();
                HtmlTableCell htmlTableCell2 = new HtmlTableCell();
                htmlTableCell2.InnerHtml = "chen";
                htmlTableRow2.Cells.Add(htmlTableCell2);
                htmlTable.Rows.Add(htmlTableRow2);            this.form1.Controls.Add(htmlTable);
            } protected void Button2_Click(object sender, EventArgs e)
            {
                HtmlTable htmlTable = (HtmlTable)this.form1.FindControl("HtmlTable1");
                Response.Write(htmlTable.Rows[1].Cells[0].InnerHtml.ToString());
            }
      

  2.   

    先感谢楼上的基本回答,runat=‘server’ 我已经加上,下面是自动生成的tablepage_load()
    {
     InitTable() //生成自定义表
    }
         
    点击save button后,获取a,b的value,
    TextBox txt = (TextBox)this.form1.FindControl("090de4b3-f174-448e-b0bb-cf458454f816");
    但返回的是null,很奇怪,我去find这个Table的ID,却能找到 :(  
    <table id="752cb166-99f2-4768-a89a-dcc25d196bb4" style="width:98%;" width="98%" border="0" cellpadding="0" cellspacing="0">
    <tr style="background-color:#cccccc;">
    <td colspan="5" align="left">test1</td>
    </tr>
    <tr class="edit">
    <td width="100">a:</td>
    <td><input name="ctl08" type="text" value="aaa" maxlength="12" runat="server" id="090de4b3-f174-448e-b0bb-cf458454f816" /></td>
    <td width="100">b:</td>
    <td><input name="ctl11" type="text" maxlength="12" runat="server" id="a4f78481-40fc-4adf-833f-2c5a32bad4d3" /></td>
    </tr>
    <tr>
    </tr>
    </table>