Tuesday, March 13, 2012

TextBox align=right?

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"Bjorn Sagbakken" <bjo-sag@.online.no> wrote in message
news:T8idnUbcV6IJ7OPbRVnzvAA@.telenor.com...

> Is there a way to right align the text in a textbox?
<asp:TextBox ID="MyTextBox" runat="server" style="text-align:right;" />
http://www.markrae.net
"Mark Rae" <mark@.markNOSPAMrae.net> wrote in message
news:O6k2GSmtHHA.3556@.TK2MSFTNGP05.phx.gbl...
> "Bjorn Sagbakken" <bjo-sag@.online.no> wrote in message
> news:T8idnUbcV6IJ7OPbRVnzvAA@.telenor.com...
>
> <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
"Bjorn Sagbakken" <bjo-sag@.online.no> wrote in message
news:ufidnZCs671E6OPbRVnzvAA@.telenor.com...
> "Mark Rae" <mark@.markNOSPAMrae.net> wrote in message
> news:O6k2GSmtHHA.3556@.TK2MSFTNGP05.phx.gbl...
> 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
>
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message
news:%23oE8d8ntHHA.5028@.TK2MSFTNGP02.phx.gbl...
> 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

0 comments:

Post a Comment