简体   繁体   中英

create dynamic controls with div in asp.net

I want to create dynamic div with controls inside it. my code is below.

TextBox tb_name = new TextBox();
tb_name.ID = Guid.NewGuid().ToString();
panel.Controls.Add(new LiteralControl("<div class='form-group'><div class='clearfix' style='margin-top:15px;'></div><div class='row'><div class='col-md-3'></div><div class='col-md-3'>"+tb_name +"</div></div></div>"));

But it is displaying like System.Web.UI.WebControls.TextBox . How to solve it?

您可以尝试以下方法: <input type='text' id='" + Guid.NewGuid().ToString() +"' runat='server'/>因此完整的代码如下所示:

  panel.Controls.Add(new LiteralControl("<div class='form-group'><div class='clearfix' style='margin-top:15px;'></div><div class='row'><div class='col-md-3'></div><div class='col-md-3'><input type='text' id='" + Guid.NewGuid().ToString() +"' runat='server'/></div></div></div>"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM