This is a migrated thread and some comments may be shown as answers.

Force uppercase characters?

8 Answers 2019 Views
Input
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 15 Apr 2009, 08:16 AM
How can I force a textbox to make all letters uppercase?

8 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 15 Apr 2009, 09:16 AM
Hi Rick,

Yes, you can.

By using the control's API you can take the current value, use the toUpperCase() Javascript method to transform it and set it back as the control's value.

http://www.telerik.com/help/aspnet-ajax/input_clientsidebasics.html

http://www.telerik.com/help/aspnet-ajax/input_clientsideradtextbox.html

http://www.telerik.com/help/aspnet-ajax/input_clientsideevents.html

All the best,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Rick
Top achievements
Rank 1
answered on 15 Apr 2009, 10:00 AM
Thanks Dimo,

I can see how it works on the ValueChanged/ValueChanging events, but these only work after the textbox loses focus.

Ideally I would want to catch the keypresses themselves and convert them to uppercase. The following example seems close, but there doesn't seem an option to set_keyCharacter() in the following example.

http://www.telerik.com/help/aspnet-ajax/input_clientsideonkeypress.html
0
Princy
Top achievements
Rank 2
answered on 15 Apr 2009, 11:44 AM
Hello Rick,

Try out the following code snippet and see whether it working as you expected.

ASPX:
 
<telerik:RadTextBox ID="RadTextBox1"  runat="server">  
 <ClientEvents OnKeyPress="UpperCaseOnly" /> 
</telerik:RadTextBox> 

JavaScript:
 
<script type="text/javascript">  
function UpperCaseOnly(sender, eventArgs)  
{      
    var c = eventArgs.get_keyCode();  
    if (c<65 || c>90)       
        window.setTimeout("$find('<%= RadTextBox1.ClientID %>').SetTextBoxValue($find('<%= RadTextBox1.ClientID %>').GetTextBoxValue().toUpperCase());",50);                
}  
</script> 

Thanks,
Princy.
0
Rick
Top achievements
Rank 1
answered on 15 Apr 2009, 11:54 AM
Hi Princy,

Why do we have to use the SetTimeout function to achieve this?
0
benitolopez_sistemas
Top achievements
Rank 1
answered on 15 May 2010, 07:17 PM
.
0
Jonathan
Top achievements
Rank 1
answered on 27 Dec 2010, 01:56 AM
Y'know, a far simpler solution is to:

1. Create a CSS style:

.allcaps
    text-transform: uppercase
}

2. Set your input field to that CSS style:

<input id="Text1" class="allcaps" type="text" />

If you're doing this for a RadGrid autogenerated textbox field, ensure that you:

2a. add a GridTextBoxColumnEditor to your form;
2b. set it to use the allcaps CSS class you created in step 1 then;
2c. Set the RadGrid column's ColumnEditorID property in the RadGrid property builder to this GridTextBoxColumnEditor.

This will give your input text an ALL CAPS look as the user types, even if Caps Lock is not enabled on the keyboard.

3. Finally, update your input field to use its own value as uppercase:

TextBox1.Text = TextBox1.Text.ToUpper()

This will work even on RadGrid input fields. Just put the code in step #3 in the RadGrid.InsertCommand event.

Enjoy.
Jonathan
0
John
Top achievements
Rank 1
answered on 27 Jul 2016, 06:44 PM
I know this is an old post but I found this an awesome solution!
0
Chamara
Top achievements
Rank 1
answered on 11 May 2018, 06:42 AM

[quote]John said:I know this is an old post but I found this an awesome solution![/quote]

can you tell us also your awesome solution?

 

Tags
Input
Asked by
Rick
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Rick
Top achievements
Rank 1
Princy
Top achievements
Rank 2
benitolopez_sistemas
Top achievements
Rank 1
Jonathan
Top achievements
Rank 1
John
Top achievements
Rank 1
Chamara
Top achievements
Rank 1
Share this question
or