Slide 12.8: Hidden fields
Slide 12.10: Events (cont.)
Home

Events


An event is an action that is usually initiated outside the scope of a program and that is handled by an event handler, which is a subroutine that executes code for a given event.

Event Handlers
Look at the following code. When will the code be executed? The answer is: “You don’t know...”

 <% lbl1.Text="The date and time is " + DateTime.Now; %> 
 <html><body>
   <form runat="server"> 
     <h3><asp:label id="lbl1" runat="server" /></h3>
   </form>
 </body></html>

The Page_Load Event
The Page_Load event is one of many events that ASP.NET understands. The Page_Load event is triggered when a page loads, and ASP.NET will automatically call the subroutine Page_Load, and execute the code inside it. The property DateTime.Now returns the current date and time according to the setting of your computer’s system date and time.


demo_pageload.aspx

Web
<%@ Page Language="C#" %>
<script language="C#" runat="server">
 protected void Page_Load( object sender, EventArgs e ) {
  lbl1.Text = "The date and time is " + DateTime.Now;
 }
</script>

<html>
 <body>
  <form runat="server">
   <h3><asp:label id="lbl1" runat="server" /></h3>
  </form>
 </body>
</html>