ASP.NET - Convert the text in a text box to upper case

Before I show you this piece of code, I have to tell a story.

I received a request to build a web application that allowed a user to enter an ID and then using that ID as the customer number, enter SOP invoices. eConnect, all that stuff.

I didn't like the fact that the ID would come over in lower case sometimes, becuause CUSTNMBRs in Dynamics are all upper case. So I found this neat piece of code to convert a text box to upper case...

And the customer didn't like it, they made me take it out.

Anyway, for the record, the code below will convert the text typed into a text box to upper case

<script type="text/javascript">
    var textBox;
    var text = new String();
    function OnKeyPress(sender, args) {
        textBox = sender;
        text = args.get_keyCharacter();
        text = sender.get_textBoxValue() + text.toUpperCase();
        setTimeout("textBox.set_value(text);", 100);
    }  
 
</script> 
    <asp:Label id="lblError" runat="server" CssClass="error"></asp:Label>
    <table border="0" style="height:200pxwidth:100%">
        <tr>
            <td style="text-align:center">
                Enter User Name (NetID) 
                <telerik:RadTextBox ID="txtNetID" runat="server" CssClass="control" Skin="" MaxLength="15" 
                    Style="text-transformuppercase;" >
                    <ClientEvents OnKeyPress="OnKeyPress" /> 
                 </telerik:RadTextBox>
            </td>
        </tr>
        <tr>
            <td style="text-align:center">
                <asp:CheckBox ID="chkPersonalUse" runat="server" /> Personal Use
            </td>
        </tr>
        <tr>
            <td style="text-align:center"><telerik:RadButton ID="btnContinue" runat="server" Text="Continue"></telerik:RadButton></td>
        </tr>
    </table>

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences