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

Force Capitals

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I am using ASP.NET And VB ...is there a way to force capital letters in a text box??

any help would appreciated
Thanks

 
The KeyPress event of your textbox will be fired for each keystroke, giving you a chance to examine and modify each character.

For example lowercase "a" has an ascii code of 96, uppercase "A" is 64. You could simply subtract 32 from 96 and you're done.

The keyvalue is passed to the KeyPress event as an integer.

Dimandja
 
dv: do you need the uppercase to appear instantly? If not you could use the UCase function in code behind:

Code:
myText.Text = UCase(myText.Text)

..otherwise I would think you might have to impliment a java solution.

 
dv: I posted at the same time as Dimandja, if you need to instantly switch to uppercase while typing each character you'll have to impliment a technique such as Dimandja described.
 
I like BB's way

<asp:TextBox id="TextBox1" runat="server" onChange="javascript:this.value=this.value.toUpperCase();"></asp:TextBox>

Marty
 
should have been

<asp:TextBox id="TextBox1" runat="server" onKeyUp="javascript:this.value=this.value.toUpperCase();"></asp:TextBox>

Marty
 
Thanks guys...Yes I need to show caps as they type..I am so used to VB6 with lost Focus etc..

<asp:textbox id="txtGen" style="Z-INDEX: 138; LEFT: 301px; POSITION: absolute; TOP: 254px" tabIndex="6" runat="server" OnTextChanged ="javascript:this.value=this.value.touppercase();" Font-Bold="True" Font-Names="Verdana" Font-Size="XX-Small" Width="288px"></asp:textbox>

the only option close to onchange or onkeyup is Ontextchanged..

I am not a java guy so forgive me..

 
hi dvannoy


try "javascript:this.value=this.value.toUpperCase();"

with html textinput instead of web controls. This will work surely and u can make your text input as a server side element at the same time.

 
You can add "text-transform:uppercase" in style.
it's work, just like VB.NET.

<asp:textbox id="txtGen" style="Z-INDEX: 138; LEFT: 301px; POSITION: absolute; TOP: 254px; text-transform:uppercase" tabIndex="6" runat="server" OnTextChanged ="javascript:this.value=this.value.touppercase();" Font-Bold="True" Font-Names="Verdana" Font-Size="XX-Small" Width="288px"></asp:textbox>

Thx
Angela Tj.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top