ASP.net three ways to realize static page cumulative access-practical tips

Source: Internet
Author: User
Static page statichtml.html
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Statistical methods for dynamic page traffic </title>
<body>
This is displayed in the layer
<div id= "PV" ></div>
<script src= "Addnumber.aspx" ></script>
</body>

Cumulative page Addnumber.aspx
<%@ Page language= "C #" autoeventwireup= "true" codefile= "AddNumber.aspx.cs" inherits= "Addnumber"%>
AddNumber.aspx.cs
Code
Copy Code code as follows:

public partial class AddNumber:System.Web.UI.Page
{
private static int count = 1;
protected void Page_Load (object sender, EventArgs e)
{
count++;
Response.Write ("var Pv=document.getelementbyid" (' PV '); Pv.innertext= "+ count +"; ");
}
}

The second method:
Static page statichtml.html
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Statistical methods for dynamic page traffic </title>
<body>
This is displayed using a picture

</body>

Cumulative page Imageaddnumber.aspx
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "ImageAddNumber.aspx.cs" inherits= "Imageaddnumber"%>

ImageAddNumber.aspx.cs
Code
Copy Code code as follows:

public partial class ImageAddNumber:System.Web.UI.Page
{
private static int count = 1;
protected void Page_Load (object sender, EventArgs e)
{
count++;
String PV = count. ToString ();
System.Drawing.Bitmap image = new System.Drawing.Bitmap ((int) math.ceiling (PV. Length * 12.5)), 22);
Graphics g = graphics.fromimage (image);
Picture background color
G.clear (Color.White);
Font font = new System.Drawing.Font (Arial), (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush (New Rectangle (0, 0, image.) Width, image. Height), Color.White, color.red, (float) 1.2f, true);
g.DrawString (pv,font, brush, 0, 0);
G.drawrectangle (New Pen (Color.gold), 0, 0, image. Width-1, image. HEIGHT-1);
System.IO.MemoryStream ms = new System.IO.MemoryStream ();
Image. Save (MS, SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.GIF);
Response.clearcontent ();
Response.ContentType = "Image/gif";
Response.BinaryWrite (Ms. ToArray ());
}
}

The third method:
Static page statichtml.html
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Statistical methods for dynamic page traffic </title>
<body>
This is implemented using AJAX
<div id= "AJAXPV" ></div>
<script language= "javascript" type= "Text/javascript" >
function Addpv () {
Building a XMLHttpRequest object across browsers
var xmlhttp;
try{
xmlhttp= new ActiveXObject (' msxml2.xmlhttp ');
}catch (e) {
try{
xmlhttp= new ActiveXObject (' microsoft.xmlhttp ');
}catch (e) {
try{
xmlhttp= new XMLHttpRequest ();
}catch (e) {}
}
}
Create a request
Xmlhttp.open ("Get", "Ajaxpv.aspx?news=1");
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate==4) {
if (xmlhttp.status==200) {
To determine whether a user name exists based on ResponseText
var Repv=xmlhttp.responsetext;
var Mypv=document.getelementbyid ("AJAXPV");
MYPV.INNERHTML=REPV;
/*alert (REPV);
}else{
Alert ("Network failure. ");
}
}
} ;
Xmlhttp.send (NULL);
Window.settimeout ("ADDPV", 1000);
}
WINDOW.ONLOAD=ADDPV;
</script>
</body>

Cumulative page Ajaxpv.aspx
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "AjaxPv.aspx.cs" inherits= "AJAXPV"%>

AjaxPv.aspx.cs
Copy Code code as follows:

public partial class AjaxPv:System.Web.UI.Page
{
private static int count=1;
protected void Page_Load (object sender, EventArgs e)
{
Add to Database
Reading data in the database, currently
Count = 5;
Response.Write (count);
}
}

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.