How to get the TextBox Value in a dynamically created HtmlTable???

R

Raed Sawalha

Hi,

This is probably pretty simple but...

I am dynamically adding rows to a HtmlTable that contain Textbox controls.
(There may be more than one server control/textbox in a given cell)

How do I get the value of a textbox when the form is posted back?

I would expect something like:

TextBox t = (TextBox)Table1.Rows[0].Cells[0].Controls[0];
String s = t.Text;

(I may be using the controls colletion incorrectly...)

Or at least that is the kind of solution I'm looking for...
 
J

Juno

Hi,

Table cann't persist its status between postback. So you have to create it
every time and add controls as well.

Or you can use request.form("yourtextboxid") to get textbox value directly.
But you still need to create table to display on the page.
 
G

Guest

from my part of view this is not simply at all.
first you should make an custom control derived from textbox which implement
IPostBackDataHandler and on
public bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
save somewhere in session your data. Session["key"] =
postCollection[postDataKey].ToString();
You cand override prerender on control to put your data back. this.Text =
Session["key"].ToString();
I think you better make a class to do this stuff for saving and getting you
data from session for all your dynamical controls.
So, this is very simple. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top