You must Sign In to post a response.
  • Category: ASP.NET

    In textbox only first letter should be capital after enter letter

    Hello,

    I need to display only first letter should change to capital after entering.

    In the below url all the letters are changing.

    http://www.dotnetspider.com/forum/272729-Automatic-Capital-Letter-Textbox.aspx

    Please help.

    Thanks
  • #762083
    Hi Syed ,

    You can create one extension method and use it
    Frorm Code :

    string name="dotnetspider";
    name=name.ToUpperCaseFirstLeter();

    Output:
    Dotnetspider

    Extension Method:

    public static string ToUpperCaseFirstLeter(this string value)
    {
    if (string.IsNullOrEmpty(value))
    {
    return string.Empty;
    }
    char[] strchar = value.ToCharArray();
    strchar [0] = char.ToUpper(strchar [0]);
    return new string(strchar);
    }

    J.Suthahar
    www.jssuthahar.com
    Be Simple Be Sample

  • #762100
    Hi

    Use the below code to make first character to capital letter.

    Place label textbox and button.


    protected void Button1_Click(object sender, EventArgs e)
    {
    char ch;
    string s = TextBox1.Text;
    ch = char.ToUpper(s[0]);
    StringBuilder sb=new StringBuilder();

    for (int i = 1; i < s.Length; i++)
    {
    sb.Append(s[i]);
    }
    TextBox1.Text=ch.ToString()+sb;
    }

    I have attached the out put screen shot.

    choose as best answer, if you are satisfied.

    Regards,

    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

    Delete Attachment

  • #762103
    Hi
    You can try this Javascript for client side
    working Good



    <script type="text/javascript">
    function GotoUpper(textboxid, str) {
    var fstChr = str.charAt(0);
    var rmStr = str.slice(1);
    str = fstChr.toUpperCase() + rmStr;
    document.getElementById("TextBox1").value = str;
    }
    </script>


    In html Code


    <asp:TextBox ID="TextBox1" onkeyup="javascript:GotoUpper(this.id, this.value)" runat="server"></asp:TextBox>


    I have attached Snapshot given below

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #762104

    Hello Syed Thahir Hussain,

    Refer the below code :

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function initCap(str) {
    /* First letter as uppercase, rest lower */
    var str = str.substring(0, 1).toUpperCase() + str.substring(1, str.length).toLowerCase();
    document.getElementById('TextBox1').value = str;
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" onblur="return initCap(this.value)" runat="server"></asp:TextBox>
    </div>
    </form>
    </body>
    </html>


    Hope this will help you.


    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments