Controls in UserControl: why empty?

A

Axel Dahmen

Hi,

I've created a UserControl containing an <asp:Repeater> control, containing an <asp:Checkbox> control:

/-------------------------
<asp:Repeater Runat="server" ID="propRpt">
<ItemTemplate>
<tr><td>
<asp:CheckBox Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Description")%>' TextAlign="Right"/>
<asp:Literal Runat="server" Visible="False" Text='<%#DataBinder.Eval(Container.DataItem,"ID")%>'/>
</td></tr>
</ItemTemplate>
</asp:Repeater>
\-------------------------


On Page_Load (!PostBack), the <asp:Repeater> gets filled by database:

/-------------------------
propRpt.DataSource=...;
propRpt.DataBind();
\-------------------------


On PostBack I want to iterate through the checkboxes to retrieve their values:

/-------------------------
foreach (RepeaterItem ri in propRpt.Controls)
{
if (((CheckBox)ri.Controls[1]).Checked)
ret[idx++]=Convert.ToInt16(((TextBox)ri.Controls[2]).Text);
}
\-------------------------

However, "(CheckBox)...Checked" always yields false!?! Can someone please enlighten me on the reason? What did I do wrong?

Even more strange: If the page is displayed on Postback, the checked Checkboxes are actually displayed as being checked...


I'm having the same problem with a second UserControl of mine which is resembling the first but uses Textboxes instead of the Checkbox. I can't evaluate their values, too. Nonetheless, after PostBack they show the values I've entered. So it's not kind of an "EnableViewState problem".

TIA,
Axel Dahmen
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top