如何引用在运行时创建的动态文本框?
我有一个引用 WCF 服务的 ASP 项目。正好满足我需要的一半。
页面上的按钮调用 WCF 中的函数,该函数返回对象列表(变量名称)。返回时,vb 代码动态地将文本框添加到页面上的面板中。像这样:
For Each LetterVariables In LetterVarList
tb = New TextBox
lb = New Label
lb.Text = LetterVariables._key & " "
tb.ID = LetterVariables._key
pnlVars.Controls.Add(lb)
pnlVars.Controls.Add(tb)
Dim LineBreak As LiteralControl = New LiteralControl("<br />")
pnlVars.Controls.Add(LineBreak)
Next
现在的问题是,完成后用户将在这些文本框中输入一些值。当用户单击另一个按钮时,我(以某种方式)需要引用这些文本框来获取值。
我该怎么做?
谢谢, 贾森
I have an ASP project which references a WCF service. Does exactly half of what I need.
A button on the page calls a function from the WCF, which returns a list of objects (variable names). When returned, the vb code dynamically adds textboxes to a panel on the page. Like this:
For Each LetterVariables In LetterVarList
tb = New TextBox
lb = New Label
lb.Text = LetterVariables._key & " "
tb.ID = LetterVariables._key
pnlVars.Controls.Add(lb)
pnlVars.Controls.Add(tb)
Dim LineBreak As LiteralControl = New LiteralControl("<br />")
pnlVars.Controls.Add(LineBreak)
Next
Now the problem is, after this is finished the user will enter some values into those texboxes. I (somehow) need to reference those texboxes to snag the values when a user clicks another button.
How can I do this?
Thanks,
Jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为 TextBox 提供一个 ID,您可以使用 FindControl 来检索该 ID。
然后当你想引用它的时候。
类似的东西可能对你有用。
You can give the TextBox an ID which you could use FindControl to retrieve.
Then when you want to reference it.
Something like that might work for you.
不要忘记在控件加载发布的值之前在回发时重新创建控件。
Don't forget to recreate the controls on post back BEFORE the controls are loaded with the posted values.