<input type='text' id='textBox' onblur='this.value = this.value.toUpperCase();'>
TextBox1.Attributes.Add("onblur", "this.value = this.value.toUpperCase();")
TextBox1.Attributes.Add("onblur", "this.value = this.value.toUpperCase();");
With the versions for ASP.NET you may want to put a check on so that it only adds this attribute in if it’s not a PostBack to the page. In the page load, it would look something like this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsPostBack = False Then TextBox1.Attributes.Add("onblur", "this.value = this.value.toUpperCase();") End If End Sub
I have seen multiple solutions that encourage the use of CSS to update the value via “text-transform: uppercase”. Beware of this solution. This will update the value on the screen to display as upper case, but when it’s posted to the server it will be posted however the user typed it (lower case for instance, even though it didn’t display on the users screen like that). If you use this, it will require you to somehow update the value posted (which is more trouble than it’s worth when the above works fine with a single line of code, in my opinion).