Last post Jun 27, 2008 01:24 PM by jkirkerx
Jun 23, 2008 02:04 PM|mkubaryc|LINK
I have been playing around with dynamically loading controls and AJAX and have the following:
An UpdatePanel has a PlaceHolder which which contains a dynamically loaded control. The control that is dynamically loaded has a button that is supposed to change the control that was loaded. So after the link button is clicked on DynamicControlA, DynamicControlB
should now be loaded where DynamicControlA used to be.
Is there anything in the framework to do this? If not, any ideas on how to tackle?
Jun 23, 2008 07:05 PM|jkirkerx|LINK
I did it with Panels. Made 5 panels all the same size, and toggled visible for the panel I needed to display. The panels contain the controls.
Panels are just div tags.
Jun 23, 2008 09:27 PM|mkubaryc|LINK
That's one way to do it I guess. It just doesn't sit right with me for some reason. What I ended up doing is the following:
Created a public method in my "ControlHub" (just a user control) that acts as a hub for the dynamic forms. Then I just have to find the control hub in each sub form and ask it to switch screens. I am sure there is a way to abstract "finding the control
hub" but for some reason I get some crazy errors when I inherit from anything other than UserControl. Something along the lines of "must inherit from UserControl or Page". My class did inherit from UserControl, but I guess it didn't like it much. Any ideas?
Jun 23, 2008 10:13 PM|jkirkerx|LINK
I have no clue what your control looks like, or how it is designed. So I have no ideas.
I've never made a user control, just server controls, so I not sure what your up against. The example below is a server controls that just switches panels. It is self contained with all code and artwork compiled into the dll.
This site is a test prototype site, not done yet. Some bugs exist. The movies are a single control, with 2 panels, one vertical and one horizontal.
Jun 25, 2008 10:51 PM|Nai-Dong Jin - MSFT|LINK
I’m not sure what does the ControlHub look like? Is it a special control to act as a hub for your dynamic forms?
You mentioned that you have involved Ajax in your application, right? In my points of view, I think the correct scenario is loading creating all of your controls
at the first time instead of loading different controls each time. So using multiView to hold your user controls can be a practice. Besides, you can expose an event from each of your user control which links to different link buttons, and assign the event
with a shared event handler that switches the ActiveViewIndex property of the multiview accordingly.
Jun 27, 2008 10:54 AM|mkubaryc|LINK
To close this post...
I was a little suprised to see everyone arguing against dynamically loading user controls, but I fell in line and used a multiview and it works nicely.
Jun 27, 2008 01:24 PM|jkirkerx|LINK
I use to use the Multiview control, but stopped using it when I started writing server controls. Can't remember why, but I think it was a design issue. Use what feels most comfortable to you.