TextBox align=right?

  • Thread starter Thread starter Bjorn Sagbakken
  • Start date Start date
B

Bjorn Sagbakken

With .NET 2.0:
Is there a way to right align the text in a textbox?
The task is to edit numbers in a table-column, and it looks kind of silly
with the numbers left-aligned.

A label respond to formatting of the table cell, but text within the texbox
doesn't.

Bjorn
 
Mark Rae said:
<asp:TextBox ID="MyTextBox" runat="server" style="text-align:right;" />

Thanks. That worked.
I was looking for something like that but didn't find anything browsing the
properties of the textbox, not even style.

Bjorn
 
Custom attributes defined on a WebControl's tag would be outputted as-is if
they are not recognized to match any typed property. Although, TextBox does
have Style property, inherited from WebControl and in this case iterating
through TextBox's Style property's keys would show text-align is there if
you specify it declaratively

<asp:TextBox ID="TextBox1" runat="server" style="text-align:right" />

foreach (string key in TextBox1.Style.Keys)
{
//Output the keys
}



--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
 
Teemu Keiski said:
Custom attributes defined on a WebControl's tag would be outputted as-is
if they are not recognized to match any typed property. Although, TextBox
does have Style property, inherited from WebControl and in this case
iterating through TextBox's Style property's keys would show text-align is
there if you specify it declaratively

<asp:TextBox ID="TextBox1" runat="server" style="text-align:right" />

foreach (string key in TextBox1.Style.Keys)
{
//Output the keys
}

Thanks. If I need to check out other keys, I will remember your tip.
I have some textboxes generated dynamically, and now I have applied a line
like this to each one of them:

ItemValue=New TextBox
ItemValue.Style("text-align")="right"

Bjorn
 
Back
Top