tags:

views:

76

answers:

1

I have a user control that when a method is called dynamically adds images to an asp panel. I have placed this control in a repeater. I am using the following code to call the function. I have tried calling this function on page_load, databinding of the repeater, databinding of the item, and oninit.

foreach (RepeaterItem repit in rpter.Items)
        {
            MyUserControl uc = rpter.FindControl("mycontrol") as MyUserControl;
            uc.MyMethod("var1","var2");
        }

The method on the usercontrol gets called, however no images show up on the page or in the source view of the page. Where am I going wrong?

+1  A: 

I'm having a hard time understanding what you're trying to do, so this answer may be off target. Can you handle the repeater's ItemDataBound event, locate the user control in the current item, and call the method directly on the user control?

Is the user control the same type for every repeater item? If so, you can cast the user control to its type instead of UserControl and call the method directly instead of getting the MethodInfo and invoking it:

UserControl uc = repit.FindControl("ucontrol") as MyUserControl;
if (uc != null)
{
    uc.MyMethod("var1", "var2", "var3", "var4");
}
Jamie Ide
I have edited my code to reflect this change. However when I call this piece of code on the repeaters ItemDataBound event, the images still don't show up on the page.
Allprob
We'd need more information on the method itself to proceed. If it were me, I would take a step back at this point and add a label and a public method to set its text to the user control. Experiment with that to remove the complexity of dynamically loading images.
Jamie Ide
The reason my images weren't coming up was related to a styling issue. Thanks for the help.
Allprob