开发者

How can I handle text boxes that are created by the client/javascript, on the server

开发者 https://www.devze.com 2023-03-06 01:55 出处:网络
I have a textbox in a form that collects a name. If the client decides he/she wants to add more names they would click add more and another textbox would appear.

I have a textbox in a form that collects a name. If the client decides he/she wants to add more names they would click add more and another textbox would appear.

If the client created 15 text boxes how can I work with their values on the server? Let's say that I name the first textbox, txtbox1, and each additional textbox would have an i开发者_开发技巧ncrementing number.

Could I use the same naming convention that Asp.net assigns, figure out how many textboxes are on the page, and loop through them, or would they have to be initially rendered by the framework to begin with?


The HttpContext.Current.Request.Params have the parameters of all submited values, even those you created using javascript, as long as the value of the text box is sent from the client to the server of course... I mean, you need to add the client-created textbox to the main form element being submited.

You can make a naming convention yourself, but take care not to collide with Asp.Net conventions as that could be trouble to you... lets say: MyTextBox_1, MyTextBox_2.

You can then iterate the HttpContext.Current.Request.Params, and see wich keys start with "MyTextBox_" and read all of them.

EDIT: better yet you can use HttpContext.Current.Request.Form, because this contains only params sent submited in the form.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号