braindead with a textbox today

R

Rob T

I think I've had too much eggnog the past couple of weeks....

If I dynamically create a text box like this:

txtTextBox = New TextBox
txtTextBox.ID = "WOF" & cnt
txtTextBox.Text = "hi"
plhResults.Controls.Add(txtTextBox)

After a postback, how do I read (or write) the value to the text box? To
read it, I guess I could do a Request("WOF" & cnt). but that doesn't seen
like the right way to do things.

Thanks.
 
S

Shiva

You will have to recreate the text box even on postback (generally in the
Page's Init event - before loading the view state) also to get its value.

I think I've had too much eggnog the past couple of weeks....

If I dynamically create a text box like this:

txtTextBox = New TextBox
txtTextBox.ID = "WOF" & cnt
txtTextBox.Text = "hi"
plhResults.Controls.Add(txtTextBox)

After a postback, how do I read (or write) the value to the text box? To
read it, I guess I could do a Request("WOF" & cnt). but that doesn't seen
like the right way to do things.

Thanks.
 
R

Rob T

This would work if I knew the name of the dynamically created text boxes and
how many, but mine are going to be created out of an unknown number of
database entries with unique id's. There's no way I can declare the
textboxes like this example........
 
W

WJ

Rob T said:
This would work if I knew the name of the dynamically created text boxes
and how many, but mine are going to be created out of an unknown number of
database entries with unique id's. There's no way I can declare the
textboxes like this example........

You will have to use the Page.FindControl method to rediscover your
dynamically created controls.

Example: If you create 3 TextBox Controls using database field names, say
F1, F2, and F3 on a Panel control named Panel1, then the sequence of
instructions would be somthing as stated below:

private void dynamControl()
{

Control pc=this.FindControl("Panel1"); //You are attempting to
find "Panel1" control on this Asp.Net page
if(pc==null)
{
return "Not very good! Please call Bill Gate for $ back";
}

Control fc=null; //make a field control
string fn="F1"; //reference database field# 1
called F1
fc=pc.FindControl(fn); //Now try to find TextBox field# 1 within
Panel1 control
if(fc==null)
{
return "No good! Shoot him!:)";
}

((TextBox)fc).Text="Something";

}

The logic for the rest of the fields are the same as for F1 above.

Hope this helps,

John Webb

}
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top