>>>>>>>>{Updated} - Solved it
>>>>>>>
>>>>>>>Do you really need to be adding these things at runtime?
>>>>>>>
>>>>>>>I find it *MUCH* easier (as someone else suggested) to add as much as possible at design time and then just control visibility or change attributes at runtime.
>>>>>>>
>>>>>>>This was cake in VFP. ASP.NET is a giant leap backward from VFP.
>>>>>>
>>>>>>IIRC the Visible property in ASP.NET doesn't really have anything in common with same VFP property. In ASP.NET with Visible=false the object in question simply won't exist.....
>>>>>
>>>>>Correct. If I want something to not show on an ASP.net page I set visible to false and it does not render at all.
>>>>
>>>>So why make a comparison between VFP and ASP.NET in this instance?
>>>
>>>Because in VFP you can do NewObject/RemoveObject and it's much harder in ASP.NET.
>>
>>RemoveObject wouldn't make much sense in a browser application ?
>>And what's hard about
form1.Controls.Add(Page.LoadControl("SomeUserControl.ascx"));
>
>Hi Viv,
>Depending on how you add the controls to start with you do have to sort of remove them on postback if you are not going to use it again. I do something like this:
>
>
> /// <summary>
> /// Display the Content Control
> /// </summary>
> /// <param name="display">AboutDisplayType</param>
> private void DisplayContent(AboutDisplayType display)
> {
> // Create a reference to each control
> ucAboutHistory historyControl = null;
> ucAboutChairmansCorner chairControl = null;
> ucAboutOrgChart chartControl = null;
> ucAboutBiography bioControl = null;
> ucAboutChapters chapterControl = null;
>
> // Check what controls are in the placeholder
> foreach (var control in this.holdAboutContent.Controls)
> {
> if (control is ucAboutHistory)
> historyControl = (ucAboutHistory)control;
>
> if (control is ucAboutChairmansCorner)
> chairControl = (ucAboutChairmansCorner)control;
>
> if (control is ucAboutOrgChart)
> chartControl = (ucAboutOrgChart)control;
>
> if (control is ucAboutBiography)
> bioControl = (ucAboutBiography)control;
>
> if (control is ucAboutChapters)
> chapterControl = (ucAboutChapters)control;
> }
>
> // Check if the controls should be displayed or not, otherwise remove them
>
> // History Control
> if (display == AboutDisplayType.History)
> {
> if (historyControl == null)
> {
> // Create the Control
> historyControl = (ucAboutHistory)this.CreateContentControl(display);
> historyControl.ID = "ucHistory";
> }
> this.holdAboutContent.Controls.Add(historyControl);
> }
> else
> {
> if (historyControl != null)
> // Shouldn't the control to be removed be "ucHistory"?
> this.holdAboutContent.Controls.Remove(historyControl);
> }
>... More
>
>
>I am sure there is a more generic way to do this but I don't have 50 different possible controls. What is nice about this approach with user controls is I can change the entire content area without navigating to a different page altogether. When you use Ajax it makes for a nicer user experience and I don't have tons of code doing visible true or false on everything. I also have seperate ascx pages that have only what is part of a single control. I like the approach quite well and use this in several sites now. If I change from About page to Resources page for instance then I change pages. I don't try to do 50 different controls on a page. Also in this case I only have one control on the page at a time, but that doesn't have to be; several could be added to the placeholder at a time easy enough as well as literal stuff.
>Tim
Hi Tim,
Where is this code called from and what is 'holdAboutContent' ?