Add counters for. Text Blog

Source: Internet
Author: User
Tags datetime tostring
Counter
I found a do not know is not Microsoft's counter, but also to foreign countries, education network in The good trouble, on their own. Text Blog
The above test a small counter control, imitate the original author's very convenient, very useful calendar control,


<%@ control language= "C #" Classname= "Dottextblogcounter" inherits= "Dottext.Web.UI.Controls.BaseControl"%>
<% @import namespace= "System.Data"%>
<% @import namespace= "System.Data.SqlClient"%>
<% @import namespace= "Dottext.Framework.Data"%>

<script runat= "Server" >
Dottextblogcounter created on 4/25/2005 by:
*daqingshu Http://blog.csdn.net/daqingshu


<summary>
Use session or cookie?
</summary>
void Page_Load (object sender, System.EventArgs e)
{
String number = "";
String strSQL = "";
String conn = Dottext.Framework.Providers.DbProvider.Instance (). ConnectionString;
HttpCookie Oldcookie = request.cookies["Counter"];
if (Oldcookie = = null)//if cookie Exist,do not count
{
HttpCookie cookie = new HttpCookie ("counter");
DateTime Dtnow = DateTime.Now;
TimeSpan Tsminute = new TimeSpan (0, 1, 0, 0);//cookie expire time 1 hour
Cookie. Expires = Dtnow + Tsminute;
RESPONSE.COOKIES.ADD (cookie);

strSQL = "UPDATE blog_config Set pagevisitcount = Pagevisitcount + 1";
Sqlhelper.executenonquery (conn, commandtype.text, strSQL, NULL);

}
strSQL = "Select Pagevisitcount from blog_config WHERE BlogID =" + Convert.ToInt32 (currentblog.blogid);
SqlDataReader RDR = Sqlhelper.executereader (conn, commandtype.text, strSQL, NULL);
if (RDR. Read ()) {
Number = Rdr[0]. ToString ();
}
Rdr. Close ();

if (number. Length <= 8)
{
for (int i = 8; I >= number. Length; I.)
{
Number = "0" + number;
}
}

Numbertopicture (number);
}


private void Numbertopicture (string number)
{
System.Web.UI.WebControls.Literal Literal1 = new Literal ();
System.Web.UI.WebControls.Literal Literal2 = new Literal ();
Literal1.text = "You are the first";
PHIMAGE.CONTROLS.ADD (LITERAL1);
if (number. Length > 0)
{
for (int i = 0; i < number. Length; ++i)
{
StringBuilder strimage = new StringBuilder ();//maybe I missing the System.Text namespace if it doesn ' t work
Strimage.append ("~/images/counter/eggblue/");
Strimage.append (Number[i]);
Strimage.append (". gif");
System.Web.UI.WebControls.Image Image = new System.Web.UI.WebControls.Image ();
Image.id = "image" + i.tostring ();
Image. IMAGEURL = Strimage.tostring ();
PHIMAGE.CONTROLS.ADD (image);
}

}
Literal2.text = "Bit Visitor". ";
PHIMAGE.CONTROLS.ADD (LITERAL2);
}


</script>
<asp:placeholder runat= "Server" id= "Phimage" ></asp:PlaceHolder>



It is really a very simple and very small function, also modified the database structure, in the table blog_config inside
Add Pagevisitcount field, when used, need to modify Pagetemplate.ascx file, add in Inside

<%@ Register tagprefix= "Overflow" tagname= "Dottextblogcounter" src= "~/skins/dottextblogcounter.ascx"%>
The right place to add
<overflow:dottextblogcounter id= "Dottextblogcounter" runat= "Server" ></overflow:DottextBlogCounter>

You have to look for a good picture.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.