label control not heeding width attribute

G

Guest

I'm trying to block out some text by setting Label width attribute which
renders as a span tag so that all labels for textfields take up the same
amount of space hence the textfields are all aligned but for some reason the
width is being ignored in IE 6 even though it works in Firefox. Is there some
bug associated with this and maybe the Doctype specification?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<style type="text/css">
..waLabel{
width:106px; /* push all textboxes to the right 106px */
margin-right:100px;
border: 1px dotted blue;
}
</style>

The FormView code:
<asp:Label ID="lblFirstName" runat="server" CssClass="waLabel" Text="First
Name" ></asp:Label>
<asp:TextBox ID="tbFirstName" runat="server" CssClass="waTextBox"
Width="180px" Columns="25" MaxLength="25" Text=' said:
</asp:TextBox>


The resulting span code:
<span id="fvRegDetail_lblFirstName" class="waLabel">First Name</span>
<input name="fvRegDetail$tbFirstName" type="text" value="Christopher"
maxlength="25" size="25" id="fvRegDetail_tbFirstName" class="waTextBox"
style="width:180px;" />

thanks for any suggestions on this.
 
G

Guest

I suggest using an HTMLTable to arrange the different controls within
tablecells. Setting the styles on tablecells is more consistent across
browsers that the inline span tag. For example,

<table class="tblClass">
<tr>
<td class="something">
<asp:Label ID="lblFirstName" runat="server" Text="First
Name" ></asp:Label>
</td>
<td class="somethingelse">
<asp:TextBox ID="tbFirstName" runat="server" Columns="25" MaxLength="25"
Text=' said:
</asp:TextBox>
</td>
</tr>
</table>
 
G

Guest

Thanks Phillip.

I thought of this but was trying to avoid the table solution as I have 50
fields so were talking 50 tr tags + 100 td tags whereas I already have the
style class assigned to the controls. But I think I'm going to have to byte
the bullet. Maybe I can get the search replace with regex to add the tags!
Did I mention I have carpal tunnel syndrome and am trying to minimize typing
;)
 
G

Guest

If I had to arrange 50 fields on a FormView I would use a repeater within the
ItemTemplate and then arrange the rows on the repeater using templates
generated dynamically by building a customized class derived from Itemplate.

Or I would use a detailsView with TemplateFields whose Templates are (again)
composed dynamically like I did in this demo albeit with a GridView:
http://www.webswapp.com/codesamples/aspnet20/itemplate/gridview.aspx

The class I developed in this demo “FormattedTemplate.cs†can be used in a
DetailsView without much of a change.
 
G

Guest

Thanks Phillip all great suggestions, but the fields are not homogenous, need
some radio button lists, checkboxes, dropdown lists and custom layout for
some sections of the page. Otherwise the DetailView would be the solution.

Derived class from ItemTemplate sounds interesting though ;)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top