Repeater, Panel, dynamic user control - can't retrieve dynamic controls in code behind

T

theComputer7

I cut down the code to make this half way understandable... I have
read Data Grid girls caution about over use of dynamic controls. I
truly believe what I am doing requires dynamically inserted user
controls.

Worse I'm trying to add dynamic user controls from within a repeater
loop (looping through attributes)... I bind to a function in the code
behind and pass in the attribute.

<asp:repeater id="rAttributes" Runat="server">
<ItemTemplate>
<asp:panel id="attPanel" runat="server"></asp:panel>
<%# InsertAttributeControl(Container)%>
</ItemTemplate>
</asp:repeater>

In the code behind I determine what type of attribute I'm dealing with
(polymorphism) and create the appropriate control to render it. I
create the control and insert it into a panel as google groups has
suggested...


// Load the UserControl.
myLB theControl = (myLB)LoadControl("../Controls/myListBox.ascx");

if (theControl != null)
{
theControl.ID = "attControl";
theControl.DataSource = theEnumAtt.Enums;
theControl.DataTextField = "EnumName";
theControl.DataValueField = "EnumID";
theControl.DataBind();

// Add control to placeholder
attPanel.Controls.Add(theControl);
}





the user updates the form and submits to a wired event..... I spin
through the repeater and get the panel (attPanel), but when I check
the attPanel.HasControls() and it returns false. It seems the dynamic
controls have disappeared.


foreach (RepeaterItem ri in rAttributes.Items)
{
// get controls
Panel attPanel = ((Panel)ri.FindControl("attPanel"));
myLB theAttEnum = ((myLB)attPanel.FindControl("attControl"));

}





Any ideas?

Thanks,

Don
 
M

Marina

Are you recreating all the dynamic controls on postback? Because they won't
recreate themselves like the controls you hard coded in your .aspx - you
have to readd them manually.
 
G

Guest

If I recreate them I can repopulate them. But all I really want to do
is get the values from the first set and redirect to another page.
There is no error handling or posts back to the page for any reason.
How do I capture the values from the elements the first submit?

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

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

Top