简体   繁体   English

在会话中存储动态创建的文本框的值

[英]storing the value of dynamically created textbox in session

I have done a project in ASP.Net that asks to input a number in textbox. 我在ASP.Net中完成了一个项目,要求在文本框中输入数字。 After typing a number in it and click a button it generates the number of textbox according to the value given in the textbox. 在其中输入数字并单击按钮后,它将根据文本框中给定的值生成文本框的数量。 Like if I type 5 in the textbox it dynamically generates 5 textboxes below. 就像我在文本框中输入5一样,它会在下面动态生成5个文本框。

I want all the value of dynamically created textbox(more than one textbox) to be stored in session and pass to next page through session after clicking another button. 我希望将动态创建的文本框(多个文本框)的所有值存储在会话中,并在单击另一个按钮后通过会话传递到下一页。 But i could not do that. 但是我做不到。

How can i solve this problem. 我怎么解决这个问题。 Anyone can help me. 任何人都可以帮助我。

Thanks 谢谢

You could create an array with the values and store that in the session. 您可以使用值创建一个数组并将其存储在会话中。 Code below is untested, but should give you an idea. 以下代码未经测试,但应该可以给您一个提示。

string[] arrayTextboxes = new string[numberOfTextboxes];
int index = 0;
foreach (Control ctrl in Page.Controls)
{
    if (ctrl is TextBox)
    {
         arrayTextboxes[index] = ((Textbox)ctrl).Text;
         index++;
    }
}

Session["tbValues"] = arrayTextboxes;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM