Argh! Trouble getting values from textbox in a Repeater

M

MattB

OK, never mind my last post. It was easy enough to refer to the table the
repeater is bound to, but I made a big, incorrect assumption in that post.

In my last post I thought I was successfully getting values from the
textboxes in my repeater. It turns out I am not and I can't see what I'm
doing wrong. I've had this problem before and just ended up taking a
different route to avoid it. Now I REALLY need to figure out what I'm doing
wrong.

This is for a configurable web survey form that is driven by SQL server
tables.

The repeater is coded like this:

<asp:repeater id=rptQuestions runat="server" DataSource="<%# DsQuestions1
%>" DataMember="questions">
<ItemTemplate>
<b>
<%#Convert.ToString(DataBinder.Eval(Container.DataItem, "qNum"))%>
. </b></td>
<%# DataBinder.eval(Container.Dataitem, "question") %>
</td>
<br>
<asp:TextBox ID="ans" Runat="server" />
</ItemTemplate>
<HeaderTemplate>
<b>Please answer as concisely as possible </b>
<br>
<br>
</HeaderTemplate>
<FooterTemplate>
</FooterTemplate>
<SeparatorTemplate>
<br />
<hr>
<br />
</SeparatorTemplate>
</asp:repeater>
-----------------------------------
It renders as I would expect using the values from the database. I also have
a "Submit" button. This is the click event:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Dim strAns As String, i As Int16, dtQs As DataTable
Dim aAns(rptQuestions.Items.Count - 1, 2) As String

dtQs = DsQuestions1.Tables("questions")

For i = 0 To rptQuestions.Items.Count - 1
Dim currentTextBox As TextBox _
= CType(rptQuestions.Items(i).FindControl("Ans"),
WebControls.TextBox)
'load up an array with answers and corresponding question IDs
aAns(i, 0) = currentTextBox.Text
aAns(i, 1) = Convert.ToString(dtQs.Rows(i)("qID"))
Next
End Sub
------------------------------------

So when I look at the values in my array, the values from the datatable (the
"qID" value) is being correctly assigned. My problem is the
currentTextBox.text is always = "" even when there is text in the box. Can
anyone tell me why I'm not getting the entered values? Please?

Thanks!

Matt
 
M

MattB

FYI - the problem was I was not putting the repeater.databind inside a If
Not IsPostBack condition. Hope that helps if anyone eles hits this issue.

Matt
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top