Using Event Tracker for ASP.NET Controls

In this article you will learn how to use ASP.NET Event Tracker to record user interaction with controls on the web page.
  • 2980

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" %>
<html xmlns="">
<head id="Head1" runat="server">
  <title>Event Tracker</title>
  <form id="Form1" runat="server">
       <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"
        <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"

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.SelectedIndex = lstEvents.Items.Count - 1
  End Sub
  Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
  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



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.


More Articles

© 2020 DotNetHeaven. All rights reserved.