TextBox align=right?

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
 
B

Bjorn Sagbakken

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
 
T

Teemu Keiski

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
 
B

Bjorn Sagbakken

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top