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

    In textbox only first letter should be capital after enter letter


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

    In the below url all the letters are changing.

    Please help.

  • #762083
    Hi Syed ,

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

    string name="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);

    Be Simple Be Sample

  • #762100

    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++)

    I have attached the out put screen shot.

    choose as best answer, if you are satisfied.


    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

    Delete Attachment

  • #762103
    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;

    In html Code

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

    I have attached Snapshot given below

    Name : Dotnet Developer-2015
    Email Id :

    '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="" >
    <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;
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" onblur="return initCap(this.value)" runat="server"></asp:TextBox>

    Hope this will help you.

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

  • Sign In to post your comments