将一个id分配给asp.net中的编程文本框

我的代码如下

public partial class newfields:System.Web.UI.Page {protected void Page_Load(object sender,EventArgs e){

    }
    protected void crtfields(object sender, System.EventArgs e)
    {
        int rowCnt;
        int rowCtr;
        Unit twidth = new Unit(600, UnitType.Pixel);
        Unit cwidth = new Unit(150, UnitType.Pixel);
        Unit cwidth1 = new Unit(300, UnitType.Pixel);
        Unit cwidth2 = new Unit(100, UnitType.Pixel);
        TableCell tcell1, tcell2, tcell3;
        rowCnt = int.Parse(tbxnofields.Text);
        for (rowCtr=1; rowCtr<=rowCnt; rowCtr++){
            TableRow tRow = new TableRow();
            tRow.Width = twidth;
            tblnoflds.Rows.Add(tRow);
            tcell1=new TableCell();
            tcell1.Controls.Add(new TextBox());
            tcell1.Width = cwidth1;
            tcell2=new TableCell();
            tcell2.Controls.Add(new TextBox());
            tcell2.Width = cwidth;
            tcell3 = new TableCell();
            tcell3.Controls.Add(new TextBox());
            tcell3.Width = cwidth2;
            tRow.Cells.Add(tcell1);
            tRow.Cells.Add(tcell2);
            tRow.Cells.Add(tcell3);
            tblnoflds.Rows.Add(tRow);
        }
    }
}

我怎样才能给我在控件中设置的文本框分配一个ID。


代替

tcell1.Controls.Add(new TextBox());

使用类似的东西

var t = new TextBox();
t.ClientIDMode = ClientIDMode.Static;
t.ClientID = "TextBox1"; //Set the ID here
tcell1.Controls.Add(t);

请参阅此处了解ClientIDMode属性的文档以及如何使用ClientID。

链接地址: http://www.djcxy.com/p/43815.html

上一篇: assigning an id to a programmed textbox in asp.net

下一篇: An invalid character was found in the mail header: ';'