tags:

views:

130

answers:

5

Hi all,

What is the best way to control the web controls position in ASP.NET page?

Back in the early days in pure HTML I use to do it with Table.

Is this still the best way?

Thank you in advance,

Roy.

+2  A: 

Tables or divs, same as any other HTML element. If you're comfortable with table-based layout and the person for whom you're making the web page doesn't mind, use tables. Otherwise, use CSS, Divs, and all of the positioning stuff that goes along with that.

Aric TenEyck
Personally I don't you should use tables for layout ever, unless you really, really can't avoid it. If you are a developer you should learn to use CSS.
Dan Diplo
A: 

You can place a web control anywhere in the asp.net page inside of regular HTML.

If you are adding the web control from the code behind the best way to get it placed is with a place holder.

HTML side could be

<div>
    <asp:PlaceHolder runat="server" id="PlaceHolder1" />
</div>

And in the code behind

Control control = //Load or create the control
PlaceHolder1.Controls.Add(control);
Bela
+2  A: 

Officially, tables are dead. Prefer CSS posistioning. WC3 Schools has some nice material on how to use. They have an in-page editor so you can put in code and try it out before you use it in your page(s).

<myControl style="postion:absolute;left:80px;top:80px" />
Muad'Dib
The problem with using that style of positioning is that you have to figure out where you want things to be ahead of time. Someone like me can figure out where things should be, relatively, on a grid (table), but ask me to position things any more accurately than that, and I'll ask to see a web designer.
John Saunders
you can also position relatively, there are a plethora of options absolute is but one of them.
Muad'Dib
+2  A: 

The modern approach is CSS positioning. Table v CSS is the type of question that everyone has an opinion on. You should research some of the pros and cons and come to your own conclusions.

To get you started:

If you're interested in CSS, I've found Stylin' With CSS to be useful.

Greg
A: 

Purely speaking about HTML you have divs you can use for laying out the page. You should always prefer them instead of HTML tables and then do the layout by using CSS. This also from an accessibility point of view, since screen readers have some problems with tables.

The same holds ASP.net web controls. You can place them inside a div which is then positioned and styled with CSS accordingly. At runtime you can attach them to containers or placeholders like the Panel control or Placeholder control. Actually the Panel control renders as HTML div later. Many of these controls have the CssClass property which again lets you specify some CSS class(es).

Juri