DJ Jester or other .NET gurus - help please

Izi

Izi

Soldato
Joined
9 Dec 2007
Posts
2,718
Scenario: I have a sidebar to my site in which widgets sit. I have 6 different templates (ascx controls) for which theses widgets could use - the template location is set in admin. All of the templates have a property which accept an object of 'SideBar' so the content of the ascx control can be populated.

Each site section has a different number of widgets in the side bars, pulled out in to a collection.

i.e:

PHP:
SideBarCollection sidebarwidgets = SideBarManager.GetSideBarBySiteSectionID(68);
            Control c;

            foreach (SideBar sideb in sidebarwidgets)
            {
                c = LoadControl(sideb.TemplateLocation);
                //i need to pass sideb to c here
                placeholder.controls.add(c);

            }

what I would do next is place the control in the page, but before I do that I need to pass to my sidebar the widget object so the template can be filled with the object data.

How would I go about passing my object to the 'unknown' control type?
 
Last edited:
You'll need to clarify a bit.

Are you trying to add "c" to "sideb"?

c will be added to the page via a placeholder.

but before adding it to the page, i need to send the object to the control to populate the data in that control, does that make sense?

i've edited my original post to try and be a bit more clear.
 
think i have worked this out. using constructor in control... albeit i am not sending the object, but sending the ID of the object to the control and getting it from cache in the control.

the simple answers are always the best.

I got it work another way but was worried about the performance. (I added all controls inside a repeater, used onitemdatabound with repeater and removed the controls which i didnt want. wasted overhead)
 
Last edited:
Back
Top Bottom