I am building an ASP.NET website that allows users to create and take tests. Tests can contain various types of questions (multiple choice, true/false, essay, etc.). Because of the dynamic nature of the tests, I am creating the "Take Test" page with repeaters.
My problem now is: how can I get the user's answers? With a fixed number/type of questions this would be simple, but I'm not sure how to grab answers from items with dynamically created IDs or how to pass a variable number of answers back to my database.
Edit: I found my answer here.
You can use Request.Form
But Here is Another approach using FindControl and Repeater:
For Each item As RepeaterItem In Me.RptItems.Items
Dim value = CType(item.FindControl("TxtName"), TextBox).Text
Next
you can use FindControl method with each RepeaterItem and find desired control inside it by ID.
ASPX file:
<asp:Repeater ID="RptItems" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>
Name
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBox ID="TxtName" runat="server" Text='<%# Eval("Name")%>'></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>