A sample how to track page usage

The function tracker will be called when browser window is closed.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”logpage.aspx.cs” Inherits=”logpage” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml&#8221; >
<head runat=”server”>
<title>Pagetracking Sample</title>

<script type=”text/javascript”>

function CallServer(str)
var product = str;
<%= ClientScript.GetCallbackEventReference(this, “product”, “ReceiveServerData”,null)%>;

function ReceiveServerData(rValue)
document.getElementById(‘_div’).innerHTML = rValue;


<body onunload =”CallServer(‘close’);return false;”>
<form id=”form1″ runat=”server”>
<div id=”_div”>



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.IO;

public partial class logpage : System.Web.UI.Page, ICallbackEventHandler
protected void Page_Load(object sender, EventArgs e)
ClientScriptManager cs = Page.ClientScript;
string er = ClientScript.GetCallbackEventReference(this, “”, “null”, “null”, “null”, true);
string rb = “function CallServer(arg) {” + er + “;}”;
cs.RegisterClientScriptBlock(this.GetType(), “CallServer”, rb, true);

#region ICallbackEventHandler

public string GetCallbackResult()

return “”;

public void RaiseCallbackEvent(string eventArgument)


private void tracker()
StreamWriter s = new StreamWriter(“C:\\closehistory.txt”);
s.WriteLine(“close at:” + DateTime.Now.ToString());



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s