如何在Asp.Net中访问动态TextBox的数据 [英] How to access dynamic TextBox's data in Asp.Net
问题描述
嗨
我有一个问题,我如何在asp.net中访问动态TextBox的数据。
我的要求是我有一个TextBox和2个按钮(button1和button2)当动态点击button1时2 TextBox应该创建之后我在TextBox中输入一些值然后当我点击button2时,2 TextBox的数据应该组合并显示在First Textbox内。
建议我怎么办。
谢谢。
hi
I have a problem that how would I access dynamic TextBox's data in asp.net.
my requirement is I have a TextBox and 2 button(button1 and button2) when click on button1 dynamically 2 TextBox's should create after that I am entering some values into the TextBox's then when I will click on button2 the 2 TextBox's data should combine and display inside the First Textbox.
Suggest me how would I do.
Thanks.
推荐答案
在button1点击事件中添加TextBox例如:
Hi,
In button1 click event add the TextBox like:
TextBox t1 = new TextBox();
t1.ID = "TextBox1";
TextBox t2 = new TextBox();
t2.ID = "TextBox2";
Panel1.Controls.Add(t1);
Panel1.Controls.Add(t2);
//Now your both textboxes are added into panel.
//You can add it wherever you want.
在button2单击事件中查找TextBox值如:
In button2 click event find TextBox value like:
TextBox t1 = (TextBox)Panel1.FindControl("TextBox1");
TextBox t2 = (TextBox)Panel1.FindControl("TextBox2");
//Now you found your both textboxes.
//Get the values using t1.Text and t2.Text
这不是太容易了。
无论如何都要尝试。
一切顺利。
--Amit
Isn't this too easy.
Anyway try it.
All the best.
--Amit
这篇关于如何在Asp.Net中访问动态TextBox的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!