如何使用C#动态添加文本框 [英] How to Add Textbox dynamically using C#
本文介绍了如何使用C#动态添加文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用C#在网页上动态添加Textbox控件.
我已将代码编写为:
TextBox tx1 =新的TextBox();
tx1.Text =动态文本框";
Page.Controls.Add(tx1);
我遇到有关runat属性的错误.
如何以编程方式将runat属性添加到文本框中
Hi,
I want to add Textbox control dynamically on the web page using C#.
i have written code as:
TextBox tx1 = new TextBox();
tx1.Text = "Dynamic Textbox";
Page.Controls.Add(tx1);
I am getting error regarding runat attribute.
How can i add runat attribute to the textbox programatically
推荐答案
选中此选项.
http://learning2code.net/Learn/2009/8/12/Adding-Controls-to-an-ASPNET-form-Dynamically.aspx [
Check this.
http://learning2code.net/Learn/2009/8/12/Adding-Controls-to-an-ASPNET-form-Dynamically.aspx[^]
Amu,
您需要在PlaceHolder控件内添加文本框.
占位符:
Hi Amu,
You need to add your text box inside a PlaceHolder control.
take a Placeholder:
<asp:placeholder id="plc" runat="server"></asp:placeholder>
然后将您的文本框对象添加到PlaceHolder:
And then add your textbox object to PlaceHolder:
TextBox tx1 = new TextBox();
tx1.Text = "Dynamic Textbox";
plc.Controls.Add(tx1);
希望对您有帮助.
祝你好运.
I hope it will help you.
Good luck.
这篇关于如何使用C#动态添加文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文