Create XML page
.........................................................................................................................................
<?xml version="1.0" encoding="utf-8" ?>
<counter>
<count>
<hits>0</hits>
</count>
</counter>
Create UserControl.aspx
.......................................................................................................................................................
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="counter.ascx.cs" Inherits="counter"%>
<asp:Label ID="lblCounter" runat="server"></asp:Label>
code usercontrol.cs page
............................................................................................................................................
protected void Page_Load(object sender, EventArgs e)
{
this.countMe();
DataSet tmpDs = new DataSet();
tmpDs.ReadXml(Server.MapPath("~/counter.xml"));
lblCounter.Text = tmpDs.Tables[0].Rows[0]["hits"].ToString();
}
private void countMe()
{
DataSet tmpDs = new DataSet();
tmpDs.ReadXml(Server.MapPath("~/counter.xml"));
int hits = Int32.Parse(tmpDs.Tables[0].Rows[0]["hits"].ToString());
hits += 1;
tmpDs.Tables[0].Rows[0]["hits"] = hits.ToString();
tmpDs.WriteXml(Server.MapPath("~/counter.xml"));
}
No comments:
Post a Comment