0

Currently I have two textboxes & one button, Suppose In One textbox1 i write sandeep gupta after clicking on button in textbox2 Sandeep Gupta is dere using the foll. code-

protected void Button1_Click(object sender, EventArgs e)
    {
        string capitalized = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(TextBox1  .Text);
        TextInfo UsaTextInfo = new CultureInfo("en-US", false).TextInfo;
       TextBox2 .Text  = UsaTextInfo.ToTitleCase(txtName .Text );
    }

I want that Text in textbox1 changes to Sandeep Gupta when i press tab to move to next field. I dont know which event to use, can u tell me!!!

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by sandeep_1987
0

Currently I have two textboxes & one button, Suppose In One textbox1 i write sandeep gupta after clicking on button in textbox2 Sandeep Gupta is dere using the foll. code-

protected void Button1_Click(object sender, EventArgs e)
    {
        string capitalized = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(TextBox1  .Text);
        TextInfo UsaTextInfo = new CultureInfo("en-US", false).TextInfo;
       TextBox2 .Text  = UsaTextInfo.ToTitleCase(txtName .Text );
    }

I want that Text in textbox1 changes to Sandeep Gupta when i press tab to move to next field. I dont know which event to use, can u tell me!!!

Hi Sandeep

1) set Autopostback Property = true of Textbox1
2)

protected Sub Textbox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtNewJobRankSerial.TextChanged
      'USE YOUR CODE.  
TextBox2 .Text  = UsaTextInfo.ToTitleCase(txtName .Text );
    End Sub

Mark as solved if it hepls you!!!

Edited by reach_yousuf: n/a

0

Try this code. It will convert the text into TitleCase using JavaScript.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript" language="javascript">
        function Trim(strIn) {
            strOut = strIn;
            strOut = strOut.replace(/^ */g, "");
            strOut = strOut.replace(/ *$/g, "");
            return strOut;
        }


        function TitleCase(oField) {

            var myValue = oField.value
            var htext = Trim(myValue);
            htext = htext.toLowerCase();

            htext = htext.substr(0, 1).toUpperCase() + htext.substring(1, htext.length);
            for (var i = 1; i < htext.length; i++) {
                if (htext.substr(i, 1) == " ") {
                    while (htext.substr(i, 1) == " ")
                        i++;

                    if (i + 1 < htext.length)
                        htext = htext.substr(0, i) + htext.substr(i, 1).toUpperCase() + htext.substring(i + 1, htext.length);
                    else
                        htext = htext.substr(0, i) + htext.substr(i, 1).toUpperCase();
                }
            }
            return htext;
        }
    
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" onblur="this.value=TitleCase(this);" runat="server" />
      <asp:TextBox ID="TextBox2" runat="server" />

        </div>
    </form>
</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.