Kaan,
I also encountered the issue of having multiple web parts when adding user control programmatically. For my application, we want controls to appear for some users and not for others. I thought programmatically adding controls was the way but abandoned the effort. Instead, I'm now using roles so the WebPartManager turns on and off the visibility of the control.
Within this thread, there is a link to Fredrik Normen's Blog. He has a post (http://fredrik.nsquared2.com/viewpost.aspx?PostID=90) that describes "Show/Hide Web Parts based on Role". I used this as a base, but instead of building a custom WebPartManager, I added the property OnAuthorizeWebPart="AuthorizingWebParts" to my WebPartManager. In the code-behind (C#), I have the protected method:
protected void AuthorizingWebParts(object sender, WebPartAuthorizationEventArgs e)
{
if (!String.IsNullOrEmpty(e.AuthorizationFilter))
{
//Advisor
if (e.AuthorizationFilter.Equals("AdvisorRole"))
{
if (!currentSession.EntitledToAdvisor) {
e.IsAuthorized = false;
} else {
e.IsAuthorized = true;
}
}
}
Some of this is specific to my application where currentSession is a custom object that I have instantiated with user information. The EntitledToAdvisor returns a boolean.