使用C#,我怎么能读动态创建文本框的内容? [英] Using C#, how can I read the content of dynamic created textboxes?

查看:539
本文介绍了使用C#,我怎么能读动态创建文本框的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海兰,

我已创建了标准内容一些动态文本框。

有谁知道我可以阅读这些文本框(假设用户修改了标准的内容),当我preSS的内容一键?

非常感谢。

杰夫

更新

这是我正在创建文本框:

 的foreach(在listOfNames字符串名称)
{
   文本框TB =新的TextBox();
   tb.Text =名称;
   tb.BorderStyle = BorderStyle.None;
   tb.BorderWidth = 0;
   tb.Font.Name =宋体;
   tb.Font.Size = 8;
}


解决方案

具体取决于您所使用的技术的不同而不同。不过,该概念将保持非常相似,尽管对于ASP.NET这将是一个更有趣一点。

的WinForms / WPF / Silverlight的

保持动态创建文本框的列表,当按钮被pressed您可以通过文本框的列表中运行,并阅读文本属性来获取用户输入。

ASP.NET - 标签更新后看来这部分是最适合您的要求。

有关ASP.NET,你将需要在OnInit方法的重写创建文本框,这应该发生在每次回发。然后在 Button.Click 事件时,可以从您在OnInit函数创建文本框读取用户输入。您需要确保该控件与相同 ID每个帖子后面创建。

Hy,

I have created some dynamic textboxes with standard content.

Does anyone know how can I read the content of these textboxes (assuming that user modified the standard content) when I press one button?

Thanks a lot.

Jeff

Update

This is how I am creating the textboxes:

foreach (string name in listOfNames)
{
   TextBox tb = new TextBox();
   tb.Text = name;
   tb.BorderStyle = BorderStyle.None;
   tb.BorderWidth = 0;
   tb.Font.Name = "Arial";
   tb.Font.Size = 8;
}

解决方案

The specific will vary depending on the technology you are using. However the concept would remain very similar, though for ASP.NET it will be a little more interesting.

WinForms/WPF/Silverlight

Maintain a list of the dynamically created textboxes and when the button is pressed you can run through the list of textboxes and read the Text property to get the user input.

ASP.NET - After the tag update it seems this section is most appropriate to your requirement.

For ASP.NET you will need to create the textboxes in an override of the OnInit method, this should happen on each postback. Then in the Button.Click event you can read the user input from the textboxes that you created in the OnInit function. You need to ensure that the controls are created with the same ID on each post back.

这篇关于使用C#,我怎么能读动态创建文本框的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆