Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding Verticle Image And Label
Message
From
26/02/2010 14:36:45
 
 
To
26/02/2010 14:05:13
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01451036
Message ID:
01451315
Views:
14
>>>>>>>>>>{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' ?
>
>holdAboutContent is a placeholder control in asp.net. This method is called from a treeview control used as a menu. I have set the Value property and handled the Node Click event. All this method does is add the appropriate control to the palce holder based on the value of the node and remove other controls that are not supposed to be there on the postback. In my case, only one control at a time is placed. ASP will require you to remove the controls that were previously there or you get a Viewstate error.
>Tim

There's something I'm missing here. If I add a control dynamically in the Page.Load it doesn't persist over round trips to the server - next Page.Load I add it again.....
How come your controls still exist ?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform