How to dynamically generate combination of ASP.NET user controls?

To add controls dynamically, you can use a panel as a place holder, say.

Up vote 0 down vote favorite share g+ share fb share tw.

I have several user controls, let's say A, B, C and D. Based on some random input, I need to generate a combination of these. For e.g. If input is 2a3d1a2c I need to show two of the A's, 3 D's after that, an A again, etc. I will also need to stabilize clientid's in order for them to work correctly.

Because each of these controls use their own ClientID property to gather the inputs on themselves. For e.g. User control A inernally generates an input named this. ClientID + "$input1", and gathers its input from request like Requestthis.

ClientID + "$input1". Since there can be more than one A, each A needs to have the same (unique) ClientID after postback in order to get correct inputs from request. Asp.net usercontrols link|improve this question edited Sep 18 '08 at 8:47Jon Limjap29.9k951101 asked Sep 18 '08 at 8:15Serhat Özgel7,429114785 78% accept rate.

I'm confused about the problem. By design the control tree must be the same on PostBack as when the page was rendered. Is there a reason why you cannot simply create the controls in order in Page.

Init each time? The framework-generated ClientID will be the same. – Adrian Clark Oct 14 '08 at 13:40.

To add controls dynamically, you can use a panel as a place holder, say Then, on the server side, you can add objects to it like so: int controlCount = 0; ... TextBox newTextBox = TextBox(); newTextBox. ID = "ctl_" + controlCount++; ControlPlaceholder.Controls. Add(newTextBox); If you add the controls to it during your Page_Load event and use a consistent method of generating the controls' IDs (such as a the simple count above) then any viewstate or event bindings will be re-bound to the right object on a postback.

If matters, it comes from a property of a class that is generated by deserializing a file (: I'll try your solution to see if it helps. – Serhat Özgel Sep 18 '08 at 8:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions