Kamis, 18 Juli 2013

How to use TextChanged event in ASP.NET

Note : Event occurs only when the AutoPostBack property of the control is set to true.
 Example of TextChanged event of the TextBox when AutoPostBack property is set to true.
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {
        int a = Convert.ToInt32(TextBox1.Text);
        int b = Convert.ToInt32(TextBox2.Text);
        int c = a + b;
        TextBox3.Text = Convert.ToString(c);
      
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
        Enter first number:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        Enter Second Number :
        <asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="True"></asp:TextBox>
        <br />
        Total : <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  
    </div>
    </form>
</body>
</html>
Output
first enter any number into first Textbox after press TAB key 
and enter second number again press TAB key , Your result will show after pressing tab key.
 
TextChanged Event of the textbox class
 

Tidak ada komentar:

Posting Komentar