trouble with DataCell Width and Width of Textbox

Discussion in 'ASP .Net' started by Jeff, Oct 8, 2008.

  1. Jeff

    Jeff Guest

    hi

    asp.net 2.0

    Below is some markup I have trouble with. The problem is that the Textbox
    doesn't fill the entire DataCell.
    I've set width of TextBox to 100%.... The point is that I want the * to be
    aligned exactly at the right corner of the TextBox. As it is now there is a
    huge space between them, maybe 30px

    <asp:Table ID="tblEditUser" runat="server" Width="370" BackColor="Gainsboro"
    >

    <asp:TableRow>
    <asp:TableCell HorizontalAlign="Right" Width="150"
    >Name:</asp:TableCell>

    <asp:TableCell Width="200" BackColor="GhostWhite"
    CssClass="columnRight">
    <asp:TextBox ID="txtName" runat="server"
    Width="100%"></asp:TextBox>
    </asp:TableCell>
    <asp:TableCell Width="20" BackColor="LavenderBlush">
    <asp:RequiredFieldValidator ID="valRequireName"
    runat="server"
    ErrorMessage="Name is required"
    ControlToValidate="txtName">*</asp:RequiredFieldValidator>
    </asp:TableCell>
    </asp:TableRow>

    Those colors above is just debug info, I want to see where each DataCell is
    ;)

    any suggestions?
    Jeff, Oct 8, 2008
    #1
    1. Advertising

  2. Here are several things to take note of:

    1. Why are you putting the TextBox and RequiredFieldValidator in separate
    TableCells?
    2. When the ErrorMessage for the RequiredFieldValidator is displayed, the
    TableCell it is in will be wider than 20
    3. When using the Width and Height properties of the TableCell, you should
    put Width="20px", not Width="20"
    4. When you are specifying the width and/or height for all cells and/or rows
    in a table (server or html), it is a good idea to include
    style="table-layout:fixed;"
    5. What happens if you add style="text-align:left;" to the TableCell with
    the RequiredFieldValidator?

    I don't have your entire code, so I can't really do a good test, but see if
    any of these suggestions make a difference. Also, just as a personal
    preference, I think it is better to use the style="..." attribute rather
    than control properties for things that are directly mapped to CSS
    properties (such as Width, Height, BackColor, etc.) when specifying them
    declaratively so that I can see them all next to each other, and also so
    that I know whether they will be rendered as CSS or an attribute of the
    rendered HTML tag. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Jeff" <> wrote in message
    news:...
    > hi
    >
    > asp.net 2.0
    >
    > Below is some markup I have trouble with. The problem is that the Textbox
    > doesn't fill the entire DataCell.
    > I've set width of TextBox to 100%.... The point is that I want the * to be
    > aligned exactly at the right corner of the TextBox. As it is now there is
    > a huge space between them, maybe 30px
    >
    > <asp:Table ID="tblEditUser" runat="server" Width="370"
    > BackColor="Gainsboro"
    > >

    > <asp:TableRow>
    > <asp:TableCell HorizontalAlign="Right" Width="150"
    > >Name:</asp:TableCell>

    > <asp:TableCell Width="200" BackColor="GhostWhite"
    > CssClass="columnRight">
    > <asp:TextBox ID="txtName" runat="server"
    > Width="100%"></asp:TextBox>
    > </asp:TableCell>
    > <asp:TableCell Width="20" BackColor="LavenderBlush">
    > <asp:RequiredFieldValidator ID="valRequireName"
    > runat="server"
    > ErrorMessage="Name is required"
    > ControlToValidate="txtName">*</asp:RequiredFieldValidator>
    > </asp:TableCell>
    > </asp:TableRow>
    >
    > Those colors above is just debug info, I want to see where each DataCell
    > is ;)
    >
    > any suggestions?
    >
    Nathan Sokalski, Oct 8, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    388
  2. AndrewF
    Replies:
    1
    Views:
    733
    Bruce Barker
    Oct 10, 2005
  3. tanmaypatankar
    Replies:
    0
    Views:
    1,065
    tanmaypatankar
    Dec 18, 2007
  4. donutman
    Replies:
    0
    Views:
    738
    donutman
    Jul 30, 2009
  5. MA

    Clickevent in datacell

    MA, Aug 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    137
Loading...

Share This Page