ASP.NET
  Home arrow ASP.NET arrow Understanding Event Handlers in ASP.NET 3....
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Understanding Event Handlers in ASP.NET 3.5
By: Codex-M
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2010-03-10

    Table of Contents:
  • Understanding Event Handlers in ASP.NET 3.5
  • ASP.NET page load event handler
  • How to create an ASP.NET click event handler
  • How to create an ASP.NET page load event handler

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Understanding Event Handlers in ASP.NET 3.5


    (Page 1 of 4 )

    ASP.NET uses event handlers to control certain behaviors. They're responsible for programs acting in certain predictable ways. If you want to master ASP.NET programming, you need to learn more about event handlers. This article will introduce you to the basics.

    Did you notice why the last web form you used acted the way it did when you clicked the submit button? Or did you notice that the time changes every time you reload an .aspx page?  Or that it greets you with “Good morning” when the time is 6 AM or “Good afternoon” when the time is 2 PM?

    These are happening because of the usage of “event handlers” in ASP.NET. “Event handlers” are called programmable “triggers” synonymous to “switch on” button of a fluorescent lamp. Once activated, it “fires” the event and causes it to execute something.

    You wouldn’t notice it, but every time you see an ASP.NET page (with .aspx extension) event handlers are activated in the process. This article explores the ASP.NET event handlers and illustrates basic coding examples of their actual use and application.

    ASP.NET “Click” event handler

    Most ASP.NET applications utilize two important types of event handlers with different applications. These are the “page load” and “click” event handlers. The “page load” event handler is triggered every time the web page is requested and loaded by the server, while the “click” event handler is triggered every time a button is clicked.

    Let's start with the more common “click” event handler. A typical working example is a web form with a submit button that utilizes the “click” event in such a way that when the submit button is clicked, ASP.NET executes a server side code associated with it. This code might be used to process form information, do form validation, submit form values to a database, and so forth.

    One of the previously covered examples utilizing “click" event handlers is in this tutorial: http://www.aspfree.com/c/a/ASP.NET/Design-and-Create-Web-Forms-in-ASPNET/. It utilizes the web form below to ask for a user input and then engages a submit button (“Compute area of the circle”):

     

    When the form is submitted, that is by clicking the “Compute area of the circle” button, the “click” event triggers the execution of the Visual Basic server side script to get user input (the circle's radius in this example) and then compute the area of the circle using the code below:

           'Get the user input radius from the text box field

            'Assigned it as userradius

            Dim Userradius As Integer = radius.Text

            'Calculate Area of the circle

            'Initiate Area as a decimal

            'Formula is 3.1416 x (r^2)

            Dim Area As Decimal

            Area = (3.1416) * ((Userradius) ^ 2)

            'Output the area of the circle back to the browser

            displayarea.Text = "The area of the circle is: " & Area

     

    If the form is not submitted, the button is not clicked. Nothing will happen to the form unless it is triggered by a click event.

    More ASP.NET Articles
    More By Codex-M


     

    ASP.NET ARTICLES

    - ASP.NET 3.5: User Access Rules
    - ASP.NET 3.5: Creating Role Based Security wi...
    - ASP.NET 3.5 Role Based Security and User Aut...
    - Canonicalizing DotNetNuke URLs in ASP.NET 3.5
    - ASP.Net 3.5: User Account Creation for Your ...
    - ASP.NET 3.5 Basic User Account Management
    - Generate Dynamic Title Tag based on QueryStr...
    - Add a Blog Module in DotNetNuke
    - ASP.NET 3.5 Basic Navigation Controls
    - Create ASP.NET 3.5 Sitemap XML for Navigatio...
    - Completing Basic DotNetNuke Website Developm...
    - DotNetNuke Website Development in ASP.NET 3.5
    - ASP.NET Querystring: Basic Dynamic URL Forma...
    - InsertItemTemplate FormView Example in ASP.N...
    - Using the FormView Web Control in ASP.NET 3.5





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek