c# - Find textbox control in ASP dynamic table -


i dynamically creating table contains textbox. doing following code:

foreach (datarow row in score_sheet.rows) // loop on rows.                 {                     int rowindex = score_sheet.rows.indexof(row); // not sure if need yet                      label label = new label();                     textbox txt = new textbox();                     txt.text = row["value"].tostring();                     txt.id = row["risk"].tostring();                     label.text = row["risk"].tostring() + "      =      ";                     rows = new tablerow();                     cell = new tablecell();                     cell.controls.add(label);                     cell2 = new tablecell();                     cell2.controls.add(txt);                       rows.controls.add(cell);                     rows.controls.add(cell2);                     ssgrid.controls.add(rows);                   } 

this adding table webpage via code:

 <asp:table id="ssgrid" runat="server"></asp:table> 

the table populating correctly, when try access updated value textbox in table null reference exception.

my find control code this:

textbox txt_any = (textbox)ssgrid.findcontrol("any");                 string anyany = txt_any.text;                 row1["value"] = any; 

how can access values being updated in textbox?

thanks!

since using dynamically generated controls here, access them or values, have recreate them when page postback. because dynamic controls lose state after have been rendered on view , way play them again after postback re-create them in code-behind.

so here, need recreate table using code use create first time.

you can put code outside if(!ispostback) code block in page_load , going this.

hope helps.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -