Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 309 Vote(s) - 3.41 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I force input to uppercase in an ASP.NET textbox?

#1
I'm writing an ASP.NET application. I have a textbox on a webform, and I want to force whatever the user types to upper case. I'd like to do this on the front end. You should also note that there is a validation control on this textbox, so I want to make sure the solution doesn't interfere with the ASP.NET validation.

**Clarification:**
It appears that the CSS text transform makes the user input appear in uppercase. However, under the hood, it's still lower case as the validation control fails. You see, my validation control checks to see if a valid state code is entered, however the regular expression I'm using only works with uppercase characters.
Reply

#2
Set the style on the textbox as [text-transform: uppercase][1]?


[1]:

[To see links please register here]

Reply

#3
style='text-transform:uppercase'
Reply

#4
Use the text-transform CSS for the front-end and then use the toUpper method on your string server-side before you validate.
Reply

#5
I just did something similar today. Here is the modified version:

<asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
<script type="text/javascript">
function setFormat() {
var inp = document.getElementById('ctl00_MainContent_txtInput');
var x = inp.value;
inp.value = x.toUpperCase();
}

var inp = document.getElementById('ctl00_MainContent_txtInput');
inp.onblur = function(evt) {
setFormat();
};
</script>

Basically, the script attaches an event that fires when the text box loses focus.
Reply

#6
CSS could be of help here.

style="text-transform: uppercase";"

does this help?
Reply

#7
**I would do like:
<asp:TextBox ID="txtName" onkeyup="this.value=this.value.toUpperCase()" runat="server"></asp:TextBox>**
Reply

#8
I realize it is a bit late, but I couldn't find a good answer that worked with ASP.NET AJAX, so I fixed the code above:

function ToUpper() {
// So that things work both on FF and IE
var evt = arguments[0] || event;
var char = String.fromCharCode(evt.which || evt.keyCode);

// Is it a lowercase character?
if (/[a-z]/.test(char)) {
// convert to uppercase version
if (evt.which) {
evt.which = char.toUpperCase().charCodeAt(0);
}
else {
evt.keyCode = char.toUpperCase().charCodeAt(0);
}
}

return true;
}

Used like so:

<asp:TextBox ID="txtAddManager" onKeyPress="ToUpper()" runat="server"
Width="84px" Font-Names="Courier New"></asp:TextBox>
Reply

#9
Use a CSS style on the text box. Your CSS should be something like this:

.uppercase
{
text-transform: uppercase;
}

<asp:TextBox ID="TextBox1" runat="server" Text="" CssClass="uppercase"></asp:TextBox>;
Reply

#10
JavaScript has the "toUpperCase()" function of a string.

So, something along these lines:

function makeUpperCase(this)
{
this.value = this.value.toUpperCase();
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through