Dynamic inputs with ASP.NET

M

MscrmGuy

Hi all:

I am trying to build a web interface for a CRM demo I am working on, and one
of the questions on the registration form is "How many children do you
have?" and then I want the user to be able to enter info for each child.

So I'd like the page to function such that if the user enters "4", the
interface updates and displays 4 input rows with textboxes for name, age,
etc. This seems to be hard to do in ASP.NET, does anyone think AJAX might be
an answer? Can anyone offer any other ideas as to how I might accomplish
this?

Thanks.
 
L

Leon Mayne

MscrmGuy said:
So I'd like the page to function such that if the user enters "4", the
interface updates and displays 4 input rows with textboxes for name, age,
etc. This seems to be hard to do in ASP.NET, does anyone think AJAX might
be an answer? Can anyone offer any other ideas as to how I might
accomplish this?

There are a few ways you could do this. Perhaps the easiest is to have your
'number of children' as a drop down control with autopostback, and also have
a hidden panel or repeater. On postback of the drop down you could
dynamically add the required number of textboxes, like so:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<br />
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True">
<asp:ListItem Selected="True">0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList><br />
<br />
<asp:panel ID="Panel1" runat="server" Height="50px"
Visible="False" Width="125px">
</asp:panel>
&nbsp;</div>
</form>


Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Panel1.Visible = True
Panel1.Controls.Clear()
For i As Integer = 1 To CInt(DropDownList1.SelectedValue)
Panel1.Controls.Add(New TextBox())
Next
End Sub

Then you just need to loop through Panel1.Controls to get the names.

HTH
 

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,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top