Slide 12.1: Web forms
Slide 12.3: Text boxes
Home

Web Forms (Cont.)


Submitting a Form
A form is most often submitted by clicking on a button. The Button server control in ASP.NET has the following format:

 <asp:Button id="id" text="label" OnClick="sub" runat="server" />

The id attribute defines a unique name for the button and the text attribute assigns a label to the button. The OnClick event handler specifies a named subroutine to execute. In the following example, a button click runs a subroutine which changes the text on the button:


demo_button.aspx

Web
<%@ Page Language="C#" %>
<script language="C#" runat="server">
 protected void submit( object sender, EventArgs e ) {
  button1.Text = "You clicked me!";
 }
</script>

<html> 
 <body>
  <form runat="server">
   <asp:Button id="button1" Text="Click me!"
     runat="server" OnClick="submit" />
  </form>
 </body>
</html>

Some other common ASP.NET events include: