Hit Counter for Application without Database:
count.ascx :
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="count.ascx.cs" Inherits="SRTT_HEALTH.uiControl.count" %>
<tr>
<td align="center" height="20">Total Visit of Web Application : <asp:Label ID="lblCounter" runat="server"></asp:Label><br>
Total No of Current Visitors : <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
</tr>
count.ascx.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace HEALTH.uiControl
{
public partial class count : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text=Application["Visitors"].ToString();
this.hitcount();
DataSet DS = new DataSet();
DS.ReadXml(Server.MapPath("~/ErrorLog/counter.xml"));
lblCounter.Text = DS.Tables[0].Rows[0]["hits"].ToString();
}
private void hitcount()
{
DataSet DS = new DataSet();
DS.ReadXml(Server.MapPath("~/ErrorLog/counter.xml"));
int hits = Int32.Parse(DS.Tables[0].Rows[0]["hits"].ToString());
hits += 1;
DS.Tables[0].Rows[0]["hits"] = hits.ToString();
DS.WriteXml(Server.MapPath("~/ErrorLog/counter.xml"));
}
}
}
count.ascx :
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="count.ascx.cs" Inherits="SRTT_HEALTH.uiControl.count" %>
<tr>
<td align="center" height="20">Total Visit of Web Application : <asp:Label ID="lblCounter" runat="server"></asp:Label><br>
Total No of Current Visitors : <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
</tr>
count.ascx.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace HEALTH.uiControl
{
public partial class count : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text=Application["Visitors"].ToString();
this.hitcount();
DataSet DS = new DataSet();
DS.ReadXml(Server.MapPath("~/ErrorLog/counter.xml"));
lblCounter.Text = DS.Tables[0].Rows[0]["hits"].ToString();
}
private void hitcount()
{
DataSet DS = new DataSet();
DS.ReadXml(Server.MapPath("~/ErrorLog/counter.xml"));
int hits = Int32.Parse(DS.Tables[0].Rows[0]["hits"].ToString());
hits += 1;
DS.Tables[0].Rows[0]["hits"] = hits.ToString();
DS.WriteXml(Server.MapPath("~/ErrorLog/counter.xml"));
}
}
}
No comments :
Post a Comment