TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)

i have place the code in the textbox1 textchanged event..

bt when i type a name it is writing it backward n it converts the last letter only in Uppercase eg... when i type geeta it show me --> Ateeg

Can u plz help me ...

Dani AI

Generated

Short answer: the weird "Ateeg" behavior comes from doing the capitalization while the user is still typing (the conversion runs on each change and moves the caret). As noted, converting inside the live change handler repositions the cursor; doing the normalization after typing avoids that.

A reliable UX is to change the value on the client when the control loses focus (no server round-trip), and to normalize again on the server when the form is submitted. Example client-side handler to make only the first character uppercase and the rest lowercase:

function capitalizeFirst(el) {
  var s = el.value.trim();
  if (!s) return;
  el.value = s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
}

Use it from the input's blur/leave event (or attach via script) so typing is not interrupted.

If server-side normalization is required (for validation or storage), do it once when processing the posted value instead of on every keystroke. For full-name title-casing use the framework helper; to uppercase only the very first character use a simple VB.NET routine:

If Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
  Dim s = TextBox1.Text.Trim()
  TextBox1.Text = Char.ToUpperInvariant(s(0)) & s.Substring(1).ToLowerInvariant()
End If

For multi-word proper case use the runtime API designed for that (for example TextInfo.ToTitleCase) — see TextInfo.ToTitleCase. Avoid relying on server-side TextChanged with AutoPostBack on because it causes repeated postbacks and cursor/reset issues (see TextBox.AutoPostBack). Also be aware of culture-specific casing (e.g., Turkish dotless/dotted i) when choosing ToUpper/ToLower or invariant variants.

Recommended Answers

All 5 Replies

Do u want all Charecters of textbox in upper case?

it cause your cursor focus in first character after converted. then your next character will input as first character.
g -> G => first converted, cursor focus on the front of first Character : |G (| : is cursor)
ge -> Eg => |Eg
gee -> Eeg => |Eeg
geet ->Teeg => |Teeg
geeta -> Ateeg => |Ateeg

commented: good explain +1

Can u help me .. i want only the first character to be uppercase that is Geeta

actually your code is great but don't use it in textbox changed event. maybe u can convert it after user fill all the textbox.

commented: Good point +1

yes u r right ...
thanks it is working perfectly now..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.