Sunday, 15 July 2012

How to set Page Hits in asp.net [Simple Method]

.Try it.... Happy Coding :):):)


C# :




protected void Page_Load(object sender, EventArgs e)
{
this.countMe();
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/counter.xml"));
lblMsg.Text = ds.Tables[0].Rows[0]["hits"].ToString();
}
private void countMe()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/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("~/counter.xml"));
}


ASPX :

...
<div><asp:Label ID="lblMsg" runat="server"></asp:Label></div>
...


Counter.xml

<counter>

<count>
<hits>
1
</hits>
<count>
<counter>

No comments:

Post a Comment