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.
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:
- Textbox - At first, add a textbox control which creates a text box where the user can input his/her name in the textbox.
- Checkbox - Now add the checkbox control where user can set the checkbox true for further continue.
- Radiobutton - Then add two radiobutton to identify that the user is visiting the site for the first time or a existing user.
- 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

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.