By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

"theComputer7" <do******@hardingmarketing.com> wrote in message
news:8c**************************@posting.google.c om...
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

Nov 16 '05 #2

P: n/a


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!
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.