How to convert entering text in textbox to LowerCase or UpperCase using Javascript in asp.net


If we want to convert Values Entering in textbox to LowerCase or UpperCase we can user onkeyup client event for textbox.
and to convert to LowerCase/UpperCase We can use Javascript Methods toLowerCase/toUpperCase.
See the following example to Understand how to use above methods…

toUpperCase:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LowerToUpper.aspx.cs" Inherits="LowerToUpper" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function ToUpper(id) {
            document.getElementById(id).value = document.getElementById(id).value.toUpperCase();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onkeyup="ToUpper(this.id)"></asp:TextBox>
    </div>
    </form>
</body>
</html>

toLowerCase:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LowerToUpper.aspx.cs" Inherits="LowerToUpper" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function ToLower(id) {
            document.getElementById(id).value = document.getElementById(id).value.toLowerCase();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onkeyup="ToLower(this.id)"></asp:TextBox>
    </div>
    </form>
</body>
</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s