Dynamic Controls

S

Scott Schluer

Hello,

I have a section of code that, once filled out and the page is posted back,
needs to repeat to allow a user to enter another set of data. Basically,
once a user fills out this small section of code, another of the exact same
set of fields should appear to allow them to enter another. This should
continue as long as they need it to. I have it set up for a single entry.
How do I dynamically add new sections of code on postback (there will be a
button, which does not yet exist which will handle the "Save and add new
dependent" event). Here's the code I have for this part. Any explanations or
links to more information are appreciated.

Thanks!

Scott

---- THIS ONLY DISPLAYS ONCE, AS A HEADER
<p><br>
List the dependents you can claim on your tax return:<br>
<span id="set5">If you complete the following, additional spaces will
appear.</span>
</p>

---- THIS SECTION NEEDS TO SAVE ENTERED DATE, THEN DYNAMICALLY ADD ANOTHER
SECTION OF THE EXACT SAME CODE WHEN A USER FILLS IT OUT AND FIRES EVENT
<p>
First Name&nbsp; &nbsp; Relationship &nbsp; &nbsp; Age<br>
<asp:TextBox ID="txtDependent" Width="208" Runat="server"
/><asp:RequiredFieldValidator ID="rfv_txtDependent"
ControlToValidate="txtDependent" CssClass="InvalidField" Display="Dynamic"
EnableClientScript="False" ErrorMessage="&nbsp;Required Field"
Runat="server" /><br>
Does this person live with you? &nbsp;
<asp:RadioButtonList ID="rdoDependentLiveWithYou"
RepeatDirection="Horizontal" Runat="server">
<asp:ListItem Value="No" >No</asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
</asp:RadioButtonList>
<asp:CustomValidator ID="cv_DependentLiveWithYou" CssClass="ErrorMessage"
Display="Dynamic" EnableClientScript="False" ErrorMessage="&nbsp;Required
Field" OnServerValidate="Dependent_Validate" Runat="server" />
</p>

In the code-behind:

Public Sub Dependent_Validate(ByVal obj As Object, ByVal e As
ServerValidateEventArgs)
e.IsValid = False

Dim LI As ListItem

For Each LI In rdoDependentLiveWithYou.Items
If (LI.Selected) Then
e.IsValid = True
Exit Sub
End If
Next
End Sub
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top