Refactor Code

  • Gravatar
    Forcing Users to Type Caps in TextBox Control

    by azamsharp on 7/30/2008 8:48:04 AM
  • This was a question posted on the ASP.NET forums. How can I make sure that everything typed in the TextBox is capitalized. The easiest way to do this is by using plain old CSS.
  • <style type="text/css">
    .t
    {
    text-transform: uppercase
    }
    </style>



    <asp:TextBox ID="txtName" CssClass="t" runat="server"></asp:TextBox>
  • Refactor it!
  • Gravatar
    Beware that this technique DOES NOT convert the input values into uppercase--it only renders the input value as uppercase. If you need to actually convert the value entered as uppercase, you'll either need to use JavaScript or convert in on the server side. rp
    by rogerpence on 7/30/2008 10:39:13 AM
  • <head>
    <title>Untitled 1</title>

    <style type="text/css">
    .t
    {
    text-transform: uppercase
    }
    </style>

    </head>
    <body>
    <form method="post">
    <input name="Text1" id="Text1" type="text" class="t" />
    <input name="Button1" type="button" value="Show value" onclick="alert( getElementById( 'Text1' ).value )"/>
    </form>
    </body>

    </html>
  • Gravatar
    Thanks! I was not aware of that! So, it only serves purpose on the UI level. I guess on the ASP.NET forums the user was much concerned about the UI. But thanks!
    by azamsharp on 7/30/2008 10:49:00 AM
Please log in to refactor the code! Login