Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting alignment in an asp:label

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
US
ok. Stupid human trick...
Ready?

How do I set text alignment on an asp:label. I am using VS 2003, and I placed a heading label that is NOT the HTML one, it's the one off the Web Forms toolbar. I did this because I want to be able to change it in code.

I looked in help, I looked on the screen...

I want to center the text inside of the label. How?

Laugh if you can, because I am.

Gary ::)
 
Hmmm...I'm not sure if you can. I thought that alignment was the responsibility of the control encapsulating it.

i.e. put a label into a table cell, then set the table cell's alignment to center (which would center the label).

D
 
You can format Web controls as you would HTML control, by adding attributes to them. I.E., (Apologies my HTML style syntax is crap and I'm away from my development machine...)

TextBox.Attributes.Add("style","Border-left: solid");

OK...

Rhys
Thought out... Maybe,
Opinionated... Probably
But it is only an opinion!
 
just wondering why you would format a label. Unless you specifically set the width of the label it doesn't matter cause it resizes to the size of the text it contains. Personally I would go with jacks suggestion and use a table cell to center the info

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Mark. When I drew the label on the grid, it sized itself. I centered it on the page. Than when I fill it with text, the text message would be in the center of the label.

Make sense, or no? Am I doing this worng?
 
Yup it does. I still would go with what jack suggested it's much simpler. Put a 1 celled 1 row table on the page center that. Throw your label into the cell, tell the cell to center it's contents, and make sure to get rid of the labels width and hieght measurements so it auto sizes.

Works like a charm

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top