Slide 12.3: Text boxes
Slide 12.5: Text boxes (cont.)
Home

Text Boxes (Cont.)


Add a Script
The contents and settings of a TextBox control may be changed by server scripts when a form is submitted. A form can be submitted by clicking on a button or when a user changes the value in the TextBox control. The following example declares three controls: When the submit button is triggered via the OnClick event, the submit subroutine is executed. The submit subroutine writes a text to the Label control:


demo_textbox.aspx

Web
<%@ Page Language="C#" %>
<script language="C#" runat="server">
 protected void submit( object sender, EventArgs e ) {
  lbl1.Text = "Your name is " + txt1.Text;
 }
</script>

<html>
 <body> 
  <form runat="server">
   Enter your name:
   <asp:TextBox id="txt1" runat="server" />
   <asp:Button OnClick="submit" Text="Submit"
     runat="server" />
   <p><asp:Label id="lbl1" runat="server" /></p>
  </form>
 </body>
</html>