Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to convert first character of every word typed in a textbox to uppercase ?
Posted
Comments
dimpledevani 22-Nov-12 5:05am    
You can use the key pressed event and find out the ascii value of the character typed and replace it by its corresponding ascii code in capita

On text change event of textbox
VB
txtbox.text = StrConv(txtbox.Text, vbProperCase)

Happy coding!
:)
 
Share this answer
 
VB
Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
        TextBox1.Text = StrConv(TextBox1.Text, vbProperCase)
    End Sub
 
Share this answer
 
you can use following javascript function :

JavaScript
function initCap(str) {
    /* First letter as uppercase, rest lower */
    var str = str.substring(0, 1).toUpperCase() + str.substring(1, str.length).toLowerCase();
    document.getElementById('TextBox1').value = str;    
}


and call that function on onblur event of text box as shown below :

C#
<asp:TextBox ID="TextBox1" onblur="return initCap(this.value)" runat="server"></asp:TextBox>
 
Share this answer
 
v2
Handle the TextBox.TextChanged event.
1) Save the TextBox.SelectionStart property.
2) Use the TextInfo.ToTitleCase Method[^] on the Text Property, saving the result in a new string variable
3) If the Text property is different from the new string, set the Text to the new string, and restore the SelectionStart property. Otherwise, do nothing.

If you don't do it this way, your cursor will move to the start of the TextBox every time you type a character (SelectionStart fixes this), or the event will enter an infinite loop (The equality test fixes this)
 
Share this answer
 
make a button event
now you make not TOLOWER not TOUPPER you make totitlecase

VB
Dim value As String = "du bi du da"
Dim title As String = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value)
Console.WriteLine(title)

'output:
' Du Bi Du Da
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900