如何从动态创建的文本框中检索值 [英] how to retrieve value from dynamically created textbox

查看:64
本文介绍了如何从动态创建的文本框中检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
单击按钮时如何从动态创建的文本框中获取价值(保存")?
我在google中尝试了所有解决方案,但找不到.
请帮助我..

Dear All,
How to take value from dynamically created textbox when clicking a button(''save'')?
I tried all the solution in google,but i could not find.
please help me..

推荐答案

动态文本框应定义为全局,并且您必须将该控件添加到表单中,例如
Dynamic Textbox should be define as global and you have to add that control into your form like
public partial class _Default : System.Web.UI.Page
{
TextBox dynamicTBox = new TextBox();
       
protected void Page_Load(object sender, EventArgs e)
{
   this.Form.Controls.Add(dynamicTBox);
}
protected void btnSave_Click(object sender, EventArgs e)
{
   Response.Write(dynamicTBox.Text);
}
}



将值输入文本框后,然后单击保存"按钮,如果发生任何服务器事件,则将丢失文本框值,在这种情况下,您需要将该文本框值存储到viewstate或session中.

如果这对您有所帮助,请投票并接受作为答案. :rose:



After entering the value into textbox and before clicking on the "save" button, If you do any server event then you will lost your textbox value and in that case you need to store that textbox value into viewstate or into session.

If this helped you then please Vote and Accept as Answer. :rose:


这篇关于如何从动态创建的文本框中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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