Serving Information Simply

Thursday 17 January 2013

Textbox textchanged event in Asp.Net




 
TextChanged is an event. It take place when the text is modified in a TextBox. With it we make a program possessed on the value of a TextBox when the user types. When the text in a TextBox is changed, we look up something in a database and display immediately the results.
 
Tip: Use TextChanged with logical tests to make your program liable and reactive to your users' actions.

The following example shows how you can use this event to respond to changes in the TextBox control. The code displays the contents of the Text property of the control in other textbox when the Text property is changed. 

  
The code that you need to write on the designer page that is webpage-example.aspx.
-------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head" runat="server">
    <title>using OnTextChanged event in TextBox</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Red">TextBox Example: OnTextChanged</h2>
        <asp:Label ID="Label1" runat="server"Text="Email"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"AutoPostBack="true"OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
        <br /><br />
        <asp:Label ID="Label2" runat="server"Text="Confirm Email></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server"BackColor="LightGoldenrodYellow"ForeColor="Crimson"></asp:TextBox>
    </div>
    </form>
</body>
</html>




 









Now We will fire the textchnaged event of textbox for showing the value of first textbox on the other text box...
For this right click on the selected textbox then into event tab there is textchanged event double click on it>>>
go through the snapshot.
   

webpage-example.aspx.cs
    protected void TextBox1_TextChanged(object sender, System.EventArgs e)
    {
        TextBox2.Text = TextBox1.Text;
    }

EXAMPLE-
---------- 
  

Thanks...
 

No comments:

Post a Comment