如何从动态创建的文本框中检索值

如何从动态创建的文本框中检索值

问题描述:

亲爱的所有人,
单击按钮时如何从动态创建的文本框中获取价值(保存")?
我在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: