How to create UserControl as webpart at runtime.



I'm adding UserControls as WebPart at runtime to a WebPartZone. This is
working fine but when I add two or more UserControl instances, the
UserControls are overlapping each other i.e. When I add first UserControl it
gets added successfully but when I add another UserControl to the same zone,
this new UserControl overlapps the first UserControl and it gives a confusing
look to the user. Also, the Title area of these webparts shows at different
areas but actual control overlaps each other.

Here is the code I'm using to create and add UserControls as WebPart:

protected void CreateWebPart(string ucName)

int index = wpzCycloneOperations.WebParts.Count - 1;

Control uc = this.LoadControl(ucName);
uc.ID = ucName + index.ToString();

GenericWebPart _wp = WebPartManager1.CreateWebPart(uc);
_wp.Title =

" ";
_wp = (

GenericWebPart)WebPartManager1.AddWebPart(_wp, wpzCycloneOperations, index +
_wp.ChromeType =

_wp.Height =



Please help me to solve this issue.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question