1

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.

1 Answer 1

3

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

Something like this...

staffContentInHerePanel.Controls.Add(new LiteralControl("</div></div>"));
1
  • Simple as that, Works like charm. I'd like to vote you up, but I'm lacking reputation. best regards.
    – Marco
    Jul 18, 2012 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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