ASP.NET label control not wrapping text in non-IE browsers

  • Thread starter Thread starter Mike Casey
  • Start date Start date
M

Mike Casey

Hello all,
I have ASP.NET label controls tied to a datasource (so
text will vary in length depending on the record). In IE
everything looks great--text is wrapped if needed. In
Netscape and Opera, the text extends horizontally and does
not wrap.

Any ideas would be most appreciated!

Thanks,
Mike
 
Have you set the width of the label? Labels render as SPAN tags in the
resulting HTML and if you have specified a width, that will appear as an
inline style attribute of the SPAN tag. If this does not work in a browser,
then that browser does not support CSS.
 
Thanks! I specify the width and height directly in the
HTML view of the page. I've noticed that making this
change within the "Style" parameters (HEIGHT: 42px; WIDTH:
100px;) works temporarily. However after recompiling the
application, the height and width attributes appear again
outside the Style tag (I assume this is because they are
set in the property window / Design view of the server
control).

I'm thinking of removing them from the properties window
and also resorting to a pure HTML control rather than a
server-based Web control, but I'm struggling with why I
have to do this.

Thanks again!
Mike
 
Mike Casey said:
Thanks! I specify the width and height directly in the
HTML view of the page. I've noticed that making this
change within the "Style" parameters (HEIGHT: 42px; WIDTH:
100px;) works temporarily. However after recompiling the
application, the height and width attributes appear again
outside the Style tag (I assume this is because they are
set in the property window / Design view of the server
control).

Not sure what you mean here. You can easily just set the width of the label
in the properties window while the page is open in design view. There's no
need to code it yourself in the HTML view.
 
I'm thinking there might be a reason in this case. If you
make changes in the properties window, the Width and
Height parameters appear by themselves in HTML, outside of
the Style tag. I'm thinking that some browsers might not
recognize these values unless they are within the Style
tag. Maybe?
 
I'm not sure you are following my instructions or you may have a problem
with your VS installation.

If I put a label on a webform and then change its height and width
properties in the property window and then run the project, I get the
following HTML sent to my client:

<span id="Label1" style="height:75px;width:100px">Label</span>

Note that the height and width are attribute values for the style attribute
of the span tag. This is the correct behavior. I'm not sure what you mean
by the parameters appearing by themselves in HTML outside of the style tag,
but if you are not getting the same results as I'm showing above, then
something is wrong.
 
AH...actually that is the HTML label you are adding,
right? If I add the Web Forms Label control, the tags are
handled differently...
 
No, that is the Web Form Label (System.Web.UI.WebControls.Label).

All web form controls render in the client as HTML, so the web form label
control renders as a span tag. Any modifications to the look/feel/position
of the label in the properties window render as style attribute values to
the span tag.

Let's see what HTML you are getting in your browser if you use a web form
label.
 
Back
Top