ASP.NET in C # implement site counter user control

xiaoxiao2021-03-06  45

----------------

Resources: Store the current count of the current count in the same class directory

0 to 9 Digital Picture of Pic Pic 0.gif ~ 9.gif

--------------------------------

AsaX file:

<% @ Control language = "c #" autoeventwireup = "false" codebehind = "counter.ascx.cs" inherits = "jianweb.counter" targetschema = "http://schemas.microsoft.com/intelliSense/ie5"%>

Runat = "Server">

-------------------

.cs file:

Namespace JianWeb

{

Using system;

Using system.data;

Using system.drawing;

Using system.Web;

Using system.Web.ui.webcontrols;

Using system.Web.ui.htmlcontrols;

///

A summary description of /// counter.

///

Public Class Counter: System.Web.ui.userControl

{

Protected system.web.ui.htmlcontrols.htmltable Table_counter;

Private Void Page_Load (Object Sender, System.EventArgs E)

{

/ / Place the user code here to initialize the page

String filepath = system.Web.httpContext.current.server.mappath ("hits.txt");

System.io.StreamReader srreadline = new system.io.streamReader

System.IO.File.Openread (FilePath),

System.Text.Encoding.ascii); // encoding.default is reading Chinese

Srreadline.basestream.seek (0, System.io.seekorigin.begin); //

String countstr = "";

IF (SRREADLINE.PEEK ()> -1)

{

CountStr = Srreadline.Readline ();

}

INT count = int.parse (countstr) 1;

Countstr = count.toString ();

SRREADLINE.CLOSE ();

Table_counter.rows [1] .cells [0] .INNNNERHTML = "";

For (int i = 0; i

{

Table_counter.rows [1] .Cells [0] .innerhtml = Table_Counter.Rows [1] .cells [0] .INNNERHTML ";

}

Table_counter.rows [1] .cells [0] .INNNERHTML = "";

// Write the string to a file.

System.io.StreamWriter file = new system.io.streamwriter (filepath);

File.WriteLine (Countstr, False);

File.Close ();

SRREADLINE.CLOSE ();

}

#Region web form designer generated code

Override protected void oninit (Eventargs E)

{

//

// Codegen: This call is necessary for the ASP.NET Web Form Designer.

//

InitializationComponent ();

Base.onit (E);

}

///

/// Designer supports the required method - do not use the code editor

// / Modify the content of this method.

///

Private vidinitiRizeComponent ()

{

This.Load = New System.EventHandler (this.page_load);

}

#ndregion

}

}

----------------------------------------- Why is it like? One sand gull in the world.

转载请注明原文地址:https://www.9cbs.com/read-75016.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.043, SQL: 9