先问下你Application["Counter"]自加拉吗

解决方案 »

  1.   

    把上面的count =Application["Counter"].ToString();改为
    count =Application["Counter+1"].ToString();还是不行啊,请教怎么修改,我asp.net才刚学,希望不要笑我的无知
      

  2.   

    把上面的count =Application["Counter"].ToString();改为
    count =Application["Counter+1"].ToString();还是不行啊,请教怎么修改,我asp.net才刚学,希望不要笑我的无知------------------------------------------
    是否刚接触计算机
      

  3.   

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CountControl.ascx.cs"
        Inherits="Count_CountControl" %>
    您是本站的第<asp:Label ID="Count" runat="server" />
    个访客 建一文本文件TextFile.txtcs:
     protected void Page_Load(object sender, EventArgs e)
        {        if (!IsPostBack)
            {
                string PathStr = Server.MapPath("TextFile.txt");
                Count.Text = ReadText(PathStr);
                int Count1 = int.Parse(ReadText(PathStr).ToString());
                Count1 = Count1 + 1;
                WriteText(PathStr, Count1.ToString());        }
        }
         public void WriteText(string pathStr, string contentText)
        {
            StreamWriter WriterStream = new StreamWriter(pathStr);
            try
            {
                WriterStream.WriteLine(contentText);
                WriterStream.Close();
            }
            catch (Exception e)
            {
                throw new NotImplementedException("无法写入!");
            }
        }
        public string ReadText(string pathStr)
        {
            string count = "";
            StreamReader ReadStream;
            ReadStream = new StreamReader(pathStr);
            if (File.Exists(pathStr))
            {
                count = ReadStream.ReadLine();
                ReadStream.Close();
            }
            return count;
        }