SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If you have multiple controls in your webpart how do you format them 'nicely' so they don't all appear in one horizontal line?

So you would have something like

  • CompanyName:
  • First Name:
  • Last Name:
  • Post code:
  • Email Address:

Is it going to have to be a table?

share|improve this question
up vote 2 down vote accepted

There is an article on A List Apart which gives an example of how to format a form without using tables

There is also a discussion on Stack Overflow which give a few more examples. One point that was made that I tend to agree with is:

"If you don't use tables you need to know the width of your labels upfront. This can often be a problem for multi-language sites (i18n).

With tables, they stretch to fit labels of differing sizes. CSS alone can't do that yet in a well-supported way." ->

share|improve this answer

The same way you format any HTML inputs on any HTML page. The webpart simply renders the HTML as you define in the render event. Use tables, divs, css styles, like any other page.

share|improve this answer
Override the RenderWebPart event to output any html you desire, e.g.: protected override void RenderWebPart(HtmlTextWriter output) { output.write("<div class='emaildiv'>"); _lblEmail.RenderControl(output); _txtEmail.RenderControl(output); output.write("</div>"); } – Anonymous May 21 '10 at 16:43

Simplest way is to add an additional LiteralControl like this in CreateChildControls:

LiteralControl lit = new LiteralControl("<br />");

Put an instance like this between all your controls, but there are so many ways to achieve this and all of that is beyond the scope of this site as it is standard ASP.Net Web Control development.

share|improve this answer

You can use Table as well as Div, SharePoint in general uses tables for most of it's built in webparts as they display the same no matter the browser.

Just be careful on how many tables you use, and nested tables are extremely bad also due to rendering times of the page.

Selecting the right container for the right situation is what should be done.

share|improve this answer
how would you use a DIV within code? – Rob May 21 '10 at 12:11
I would not recommend this approach as you're hard coding tables for layout which is bad practice. Useful to know that a Panel control renders as a div if you need a div in your web part. – Charles Lee May 21 '10 at 18:47
Avoid using tables, use divs or ul/li and CSS formatting - it allows for better formatting. – Wictor Wilen MCA MCM MVP May 22 '10 at 10:52

Your Answer


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.