ARTICLE

Using Event Tracker for ASP.NET Controls

Posted by Sapna Articles | ASP.NET using VB.NET December 28, 2010
In this article you will learn how to use ASP.NET Event Tracker to record user interaction with controls on the web page.
 
Reader Level:

Event Tracker for ASP.NET Controls

The ASP.NET Event Tracker is used to record user interaction with controls on the web page. Here we are going to add some controls to the login page and see how event tracker handle all the control changes.


Controls in the Login Page


The following code sample adds the following controls to the page:

  1. Textbox -  At first, add a textbox control which creates a text box where the user can input his/her name in the textbox.
  2. Checkbox - Now add the checkbox control where user can set the checkbox true for further continue.
  3. Radiobutton - Then add two radiobutton to identify that the user is visiting the site for the first time or a existing user.
  4. Listbox - And last add a list box to display all the changes with controls events.
Code Snippets

File: Default.aspx

<%@ Page language="vb" Inherits="EventTracker" CodeFile="Default.aspx.vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title>Event Tracker</title>
</head>
<
body>
  <form id="Form1" runat="server">
    <div>      
       <h3>Controls being monitored for change events:</h3>
       <h4>Enter Full Name</h4>
        <asp:TextBox ID="Name" runat="server"
            AutoPostBack="true" OnTextChanged="CtrlChanged" Height="18px" Width="141px" />
        <br /><br />
        <asp:CheckBox ID="checkbox" runat="server"
            AutoPostBack="true"
        <br /><br />
        <asp:RadioButton ID="option1" runat="server" GroupName="Sample"
           AutoPostBack="true" OnCheckedChanged="CtrlChanged" Text="new user"/>
        <asp:RadioButton ID="option2" runat="server" GroupName="Sample"
           AutoPostBack="true" OnCheckedChanged="CtrlChanged" Text="Existing user"/>
     
 <h3>List of events:</h3>
       <asp:ListBox ID="lstEvents" runat="server" Width="216px"
    </div>
  </form>
</body>
</html>

File: Default.aspx.vb
 
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Partial Public Class EventTracker
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
     Log("<< Page_Load >>")
  End Sub
  Private Sub Log(ByVal entry As String)
     lstEvents.Items.Add(entry)
     lstEvents.SelectedIndex = lstEvents.Items.Count - 1
  End Sub
  Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
     Log("Page_PreRender")
  End Sub
  Protected Sub CtrlChanged(ByVal sender As Object, ByVal e As EventArgs)
     Dim ctrlName As String = (CType(sender, Control)).ID
     Log(ctrlName & " Changed")
  End Sub
End Class

Output Window

eventtrackr.gif

Here we fill the textbox control with user name, mark the checkbox true to continue and select the second radiobutton, now notice that all the three changes with textbox, checkbox and radiobutton are mention in the listbox.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor