Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm in the process of working thorugh Microsofts video tutorials for developing on Sharepoint. My actual small project is to create a visual Webpart which displays a list of all registered users with their display name, department and title.

This works like a charm. Now I want to improve the design of this little piece, just for the sake of it. So I created an . How can I put my rendered controls right into this Panel?

Below is the code which is executed when the Page loads.

public partial class PeoplePickerUserControl : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string _department = null, _Title = null;
        var serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);
        var userProfileManager = new UserProfileManager(serviceContext);

        Controls.Add(new LiteralControl("<div class='ui-widget-header'>PeoplePicker<div class='ui-widget-content ui-corner-all'>"));
        foreach (UserProfile userProfile in userProfileManager)
        {
            if (userProfile[PropertyConstants.Department].Value != null)
                _department = userProfile[PropertyConstants.Department].Value.ToString();
            else _department = "";
            if (userProfile[PropertyConstants.Title].Value != null)
                _Title = userProfile[PropertyConstants.Title].Value.ToString() + ", ";
            else _Title = "";

            Controls.Add(new LiteralControl("<p><fieldset>"+ " " +"<a href='" + userProfile.PublicUrl + "'>"+ userProfile.DisplayName + "</a><br />" 
                + _Title +  _department + "</fieldset></p>"));
        }
        Controls.Add(new LiteralControl("</div></div>"));
    }
}

<asp:Panel ID="staffContentInHerePanel" runat="server">
   // Content should be put in here
</asp:Panel> 

As you can see I am rendering two divs, which I want to be styled with JQuery. This part shall be exported into the .ascx file.

Thank you in advance.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Try to use staffContentInHerePanel.Controls instead of just Controls in your code

Something like this...

staffContentInHerePanel.Controls.Add(new LiteralControl("</div></div>"));
share|improve this answer
    
Simple as that, Works like charm. I'd like to vote you up, but I'm lacking reputation. best regards. –  Serv Jul 18 '12 at 8:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.