c# - Accessing dynamically created textboxes text -


i have stumbled across problem asp.net form.

within form end user chooses number of textboxes dynamically created, works fine following code:

protected void txtamountsubmit_click(object sender, eventargs e)     {         int amountoftasks;         int.tryparse(txtamountoftasks.text, out amountoftasks);         (int = 0; < amountoftasks; i++)         {             textbox txtadditem = new textbox();             txtadditem.id = "txtadditem" + i;             txtadditem.textmode = textboxmode.multiline;             questionnine.controls.add(txtadditem);             txtlist.add(txtadditem.id);         }     } 

however has caused small problem me, later on in form on submit button click, send results specified person needs go (using smtp email). again part fine, until trying retrieve text these dynamically created textboxes.

what have tried

  1. i have tried using this msdn access server controls id method not working.

  2. i tried add these new textboxes list, unsure on how update these textboxes when have text in them. therefore results returning null because of this.

  3. i have looked @ other questions on such this wpf or winforms, rather problem asp.net (this isn't issue, don't need text every textbox control in page, ones dynamically created).

i have tried changing how call code hoped have worked:

string textboxestext = string.join("\n", txtlist.select(x => x).toarray()); 

and in concatenated string (email body) call:

textboxestext 

the problem

as dynamically created finding difficult call them id example: txtexampleid.text, have increment id's 1 each time (so don't override each other) has made things little bit more difficult me.

i not asking code solution, prefer pointers in right direction still learning.

so sum up: need text dynamically created textboxes add email body.

the issue these text boxes need recreated in load event of page, every single time, both events , values can hooked , retrieved.

i think straight forward approach, in case, extend idea #1 had tried. build list of these controls enough information recreate them in load, need store list in either viewstate or session.

viewstate["dynamiccontrols"] = list; 

or

session["dynamiccontrols"] = list; 

i use viewstate if can because gets destroyed when user leaves page.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -