Text Boxes (Cont.)


Add a Script (Cont.)
In the following example we declare one TextBox control and one Label control in an .aspx file. The following method and properties of TextBox are used in the example: When you change the value in the TextBox and either click outside the TextBox or press the Tab key, the change subroutine is executed. The change subroutine writes a text to the Label control:


demo_textbox3.aspx

Web
<%@ Page Language="C#" %>
<script language="C#" runat="server">
 protected void change( object sender, EventArgs e ) {
  lbl1.Text = "You changed text to " & txt1.Text;
 }
</script>

<html>
 <body> 
  <form runat="server">
   Change text
   <asp:TextBox id="txt1" runat="server" text="Hello World!"
      OnTextChanged="change" AutoPostBack="true"/>
   <p><asp:Label id="lbl1" runat="server" /></p>
  </form>
 </body>
</html>