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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox Alignment 2

Status
Not open for further replies.

ietprofessional

Programmer
Apr 1, 2004
267
0
0
US
Stupid Question:

How do I align a text box to the right? and put it to currency format?

Thanks!
 
In code, you can set the rtl setting like this:
TextBox1.Attributes.Add( "dir", "rtl" );

For the numeric stuff, you'll need some javascript. Something like this:

Code:
<script> 
  function EnsureNumeric() 
  { 
    var key = window.event.keyCode; 
    if(key < 48 || key > 57) 
      window.event.returnValue = false 
  } 
</script>

Where you associate the function with the keypress event:
TextBox1.Attributes.Add( "onkeypress", "EnsureNumeric();" );
 
For currency format, you can also allow any input (at first), but have a validator check to see if it is in the proper format.
 
for currency:

amount = 12.99
totalAmountLabel.Text = String.Format("{0:c}", amount)
 
Thanks BoulderBum for the info on adding the 'dir' attribute. Is there any documentation on what other attributes are available? This isn't a property that you can set in the VS form designer so I didn't even know it existed!

Regards

Nelviticus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top