views:

138

answers:

4

Here's my forms layout:

    <body>
        <p>Note that this form doesn't actually do anything 
        except illustrate the Required Field Validator.</p>

        <form id="frmValidator" method="post" runat="server">
            Usuario:
            <asp:TextBox id="txtUserName" runat="server" />
            <asp:RequiredFieldValidator id="userNameValidator" ControlToValidate="txtUserName" ErrorMessage='<img src="../Images/no.png">' runat="server" />

            <br />

            Contrasena:
            <asp:TextBox id="txtPassword" runat="server" />
            <asp:RequiredFieldValidator id="passwordValidator" ControlToValidate="txtPassword" ErrorMessage='<img src="../Images/no.png">' runat="server" />

            <br />
            <asp:button id="btnSubmit" text="Submit" runat="server" />
        </form>

        <p>Hint: Try submitting it before you enter something.</p>
    </body>

This is a simple layout for just learning purposes, but they align themselves badly. They just smooch together.

Someone suggested I just prace the 'space' key to create the whitespace between them, but that doesn't align them at all. They can never be correctly aligned.

Someone said use tables, but I loathe the idea of using tables for layout.

How can I achieve a simple organizational style between these two fields?

A: 

wrap you labels in a div with a class. Then set the min-width the label class so that it is as wide as you need it, then all your fields/labels will line up.

Paul Creasey
A: 

How about padding them so they're not smooshed together? Of course, you may want to create a css class instead of the style attribute, but you get the point.

As far as a standard for ASP.NET, just use good standard CSS. There's nothing fundamentally different with ASP.NET than any other web programming language.

<form id="frmValidator" method="post" runat="server">
            <div style="padding:5px;">
                Usuario:
                <asp:TextBox id="txtUserName" runat="server" />
                <asp:RequiredFieldValidator id="userNameValidator" ControlToValidate="txtUserName" ErrorMessage='<img src="../Images/no.png">' runat="server" />

            </div>
            <div style="padding:5px;">
                Contrasena:
                <asp:TextBox id="txtPassword" runat="server" />
                <asp:RequiredFieldValidator id="passwordValidator" ControlToValidate="txtPassword" ErrorMessage='<img src="../Images/no.png">' runat="server" />

            </div>
            <div style="padding:5px;">
                <asp:button id="btnSubmit" text="Submit" runat="server" />
            </div>
        </form>
Aaron Daniels
Thank you that illustrated padding very clearly. However, I mean the separations between: "usuario" and <textbox>. The label and the field are very close together.
Sergio Tapia
oh...try using ' ', it's a non-breaking space.
Aaron Daniels
A: 

I would try to use a template or an form generator. A great starting point for solutions is:

http://www.smashingmagazine.com/2006/11/11/css-based-forms-modern-solutions/

:-)

Robert
+1  A: 

To expand on Creasey's answer.

<div style="width=150">Usuario:</div>
<asp:TextBox id="txtUserName" runat="server" />

...

<div style="width=150">Contrasena:</div>
<asp:TextBox id="txtPassword" runat="server" />
Steve