How do you query the values of textboxes dynamically created in a Panel container??

S

SD

Hello,

I have a form that has a panel container where I'm adding textboxes
dynamically based on a query to database, so I'm looping through the
records.

The problem I have is that once built, I need to pass those textboxes values
to another for to build the parameters for a report.

Here is the sample:

While myReader.Read()
Dim txtBox As New TextBox
Dim lbLabel As New Label
parCounter = parCounter + 1

' Create dynamic controls here.
lbLabel.ID = "Label" + parCounter.ToString()
lbLabel.Text = myReader("parameter") & " "
lbLabel.Font.Bold = True
lbLabel.Font.Size = FontUnit.Parse(15)

lbLabel.ForeColor = Color.Navy
Page.Controls.Add(lbLabel)
txtBox.ID = "Textbox" + parCounter.ToString()
Page.Controls.Add(txtBox)
Page.Controls.Add(New LiteralControl("<br>"))
End While

Dim objButton As New Button
objButton.Text = " Run Report "
objButton.ID = "ButtonID"
'AddHandler objButton.Click, AddressOf ButtonID_Click
Panel1.Controls.Add(New LiteralControl("<br>"))
Panel1.Controls.Add(objButton)

So now on the postback I need to parse through all these values, but can't
find a single routine to handle this.

Any ideas???

SD
 
W

William F. Robertson, Jr.

Well, if you just need to get the values from the text box, you could do it
old Request.Forms style.

string s = null;
for( int parCounter = 0 ; parCounter == parCounter ; parCounter++ )
{
s = Request.Form["TextBox" + parCounter.ToString()];
if ( s == null ) break; //leaves for loop

//this is a value from the text box.
Response.Write( s );
}

HTH,

bill
 
G

Guest

Thanks! Your solution solved my problem and it's the easiest one to follow. I
had been searching for a fix for two days.
 
G

Guest

Thankyou also, as your answer solved my problem as well.
I have been trying to figure this out and although I have received help from
others nothing has seemed to work.

William F. Robertson said:
Well, if you just need to get the values from the text box, you could do it
old Request.Forms style.

string s = null;
for( int parCounter = 0 ; parCounter == parCounter ; parCounter++ )
{
s = Request.Form["TextBox" + parCounter.ToString()];
if ( s == null ) break; //leaves for loop

//this is a value from the text box.
Response.Write( s );
}

HTH,

bill
SD said:
Hello,

I have a form that has a panel container where I'm adding textboxes
dynamically based on a query to database, so I'm looping through the
records.

The problem I have is that once built, I need to pass those textboxes values
to another for to build the parameters for a report.

Here is the sample:

While myReader.Read()
Dim txtBox As New TextBox
Dim lbLabel As New Label
parCounter = parCounter + 1

' Create dynamic controls here.
lbLabel.ID = "Label" + parCounter.ToString()
lbLabel.Text = myReader("parameter") & " "
lbLabel.Font.Bold = True
lbLabel.Font.Size = FontUnit.Parse(15)

lbLabel.ForeColor = Color.Navy
Page.Controls.Add(lbLabel)
txtBox.ID = "Textbox" + parCounter.ToString()
Page.Controls.Add(txtBox)
Page.Controls.Add(New LiteralControl("<br>"))
End While

Dim objButton As New Button
objButton.Text = " Run Report "
objButton.ID = "ButtonID"
'AddHandler objButton.Click, AddressOf ButtonID_Click
Panel1.Controls.Add(New LiteralControl("<br>"))
Panel1.Controls.Add(objButton)

So now on the postback I need to parse through all these values, but can't
find a single routine to handle this.

Any ideas???

SD
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top