get content of text boxes dynamically created

T

tarscher

Hi all,

I create a set of text-boxes based on user input:

for (int i = 0; i < Convert.ToInt16(keywordsDropDownList.Text);
i++)
{
myTextBox = new TextBox();
myTextBox.Columns = 5;
myTextBox.ID = "parameterTextBox"+Convert.ToInt16(i);
myTextBox.TabIndex = (short) (i+1);
buttonPlaceHolder.Controls.Add(myTextBox);
}

The text boxes are followed by a button that, when clicked, should get
the content form the text boxes and put em in a database. How can I get
the content from teh text boxes?

I cannot use
someVar = parameterTextBox0.text
since it is not known

Thanks in advance
Stijn
 
T

Teemu Keiski

But you can use Page.FindControl

TextBox tb = (TextBox)Page.FindControl("parameterTextBox0");
 
E

Eliyahu Goldin

Stijn,

buttonPlaceHolder.FindControl ("parameterTextBox1") as TextBox

should do.
 
T

tarscher

Thanks for the reply. i haven't made it work yet though. It seems that
FindControl can't find the textbox since null is returned. The
textboxes are placed inside a view (and multiview) and then inside a
placeholder (suing a masterpage). Maybe this is the reason why null is
returned?

Regards,
Stijn

Teemu Keiski schreef:
 
T

tarscher

Hi all,

I tried the findcontrol with textbox I added via the editor but that
also returned a null. I used Page.findcontrol(id) and just
findcontrol(id).

Someone has an idea what I'm doing wrong?

Regards
Stijn


(e-mail address removed) schreef:
 
E

Eliyahu Goldin

You need to call FindControl on the control that directly contains the
control you are trying to find. Did you try my suggestion

buttonPlaceHolder.FindControl ("parameterTextBox1") as TextBox ?
 

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,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top