Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically generated textboxes

Status
Not open for further replies.

JaneB19

Technical User
Jun 27, 2002
110
0
0
GB
Morning All!

I'm hoping that somebody can help me with this, I tried in the VB.net forum yesterday and it was suggested I try here!

What I would like to do is dynamically generate textboxes. These textboxes are generated depending on the selected value in a radiobutton list within a webform, for example, if the selected value in the radiobutton list is '4' then 4 textboxes are generated.

I have some coding done, but I'm not too sure 1) if it is correct and 2) how do I get the textboxes to show on the form? The radiobutton list is set so that AUTOPOSTBACK = TRUE as I need the textbox values after the user clicks the SUBMIT button.

Here is my coding so far for the textboxes:

Public Sub LettersFound(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim i As Integer
Dim LettersFound As TextBox

For i = 1 To "No_Letters"
'LettersFound.Visible.ToString()
'LetFoundTable(LettersFound.Text)
i = i + 1
'Response.Write("This is the number of text boxes that should be shown" + "' & i & '")
Next

End Sub


Where "No_Letters" is the name of the radiobutton list. The maximum number of textboxes to be drawn is 12 if that helps?

The bits that are commented out are ways that I've tried to generate the textboxes and haven't worked!

Any help is greatly appreciated

Thanks in advance

Jane :)
 
Hi,

You need to new a textbox i.e.

Code:
Dim t as new textbox

You can then manipulate that textboxes property. To add it to the form you then need to add it top the container controls controls collection i.e.

Code:
parent.controls.add(t)

That is the step that you are missing. What is important is that for you to access the values in the textboxes afterwards in a postback, you need to load them with the same name every time a page_load event occurs after they are initailly added to the page. If you don't you will not be able to get at their data.

James :)


James Culshaw
james@miniaturereview.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top