静态页面是由程序动态成生的,
里面的代码是通过<script src=http://localhost/.NET/NewsFiles/ClickCount.aspx?NewsId=46></script>调用一个动态页面的。
其中:
ClickCount.aspx
<asp:Label ID="Label1" runat="server" Width="173px"></asp:Label>ClickCount.aspx.cs一开始我是这样写的
        protected void Page_Load(object sender, EventArgs e)
        {
            //string strNewsId = Request.QueryString["NewsId"].ToString();//接收传过来的新闻id
            SqlServerDataBase db = new SqlServerDataBase();
            db.Update("update inNews set ViewCount=ViewCount+1 where NewsId=46", null);
            SqlServerDataBase db1 = new SqlServerDataBase();
            DataSet ds = db1.Select("select ViewCount from inNews where NewsId=46", null);
            Response.Write(ds.Tables[0].Rows[0]["ViewCount"].ToString());
            Label1.Text = ds.Tables[0].Rows[0]["ViewCount"].ToString();        }后来在群里有人说应该这样:
        protected void Page_Load(object sender, EventArgs e)
        {
            //string strNewsId = Request.QueryString["NewsId"].ToString();//接收传过来的新闻id
            SqlServerDataBase db = new SqlServerDataBase();
            db.Update("update inNews set ViewCount=ViewCount+1 where NewsId=46", null);        }
        protected override void Render(HtmlTextWriter writer)
        {
            SqlServerDataBase db1 = new SqlServerDataBase();
            DataSet ds = db1.Select("select ViewCount from inNews where NewsId=46", null);
            Response.Write(ds.Tables[0].Rows[0]["ViewCount"].ToString());
            Label1.Text = ds.Tables[0].Rows[0]["ViewCount"].ToString();        }
------------
但这两个写法都不对,都不能现实浏览次数,但其中的更新代码是正确的,每次访问都加1。
单独访问ClickCount.aspx页面, Response.Write(ds.Tables[0].Rows[0]["ViewCount"].ToString());能显示,但 Label1.Text = ds.Tables[0].Rows[0]["ViewCount"].ToString();不能显示。请高手帮忙……谢谢……

解决方案 »

  1.   

    参考http://g.ssxz.com
    把统计做成脚本
      

  2.   

    强烈建议楼主将新闻静态页面的查看次数统计功能用 AJAX 实现
      

  3.   

    getcount.aspx?id=333
    内容:document.write("3232323");
      

  4.   

    <script 是和本页面并行运行的,怎么写都出不来你想要的效果建议改为
    <iframe src=http://localhost/.NET/NewsFiles/ClickCount.aspx?NewsId=46  frameborder="0" scrolling="no" ></iframe>测试一下效果
      

  5.   

    谢谢楼上的同志们,正在调试to songsu(松鼠) ( )强烈建议楼主将新闻静态页面的查看次数统计功能用 AJAX 实现
    -------
    能说得详细一点么
      

  6.   

    楼上所说,把统计代码放在脚本里,是不是就是放在js文件里进行计算?这个怎么样通过id来计算呢?而且有那么多的新闻纪录……不太明白,请告知
    -------
    还有就是
    document.write("3232323");
    对这句话不知道怎么用。
      

  7.   

    自己顶一下,
    用iframe页面效果不是太好
    用脚本还没弄明白,今天要搞定
      

  8.   

    在网上找到这样一种写法
                    string count = ds.Tables[0].Rows[0]["ViewCount"].ToString();
                    Response.Write("document.write(\"" + count + "\")");但访问静态新闻页面还是不显示,如果访问.aspx页面显示“document.write("88") ”,应该就是这句“Response.Write("document.write(\"" + count + "\")");”代码的问题高手指点一下吧……
      

  9.   

    <script src=http://localhost/.NET/NewsFiles/ClickCount.aspx?NewsId=46></script>要保证返回的代码复合js的语法。比如document.getElementById("Lbl_Count").InnerText = "100";那么在ClickCount.aspx.cs 的 Page_Load 最后只需要Response.Write("document.getElementById("Lbl_Count").InnerText = '100';");就可以了。另外 ClickCount.aspx 只保留第一行代码(<%@ Page ......),其他的都要去掉。
      

  10.   

    嗯,已经搞定,就是按照楼上的意思,
                    string count = ds.Tables[0].Rows[0]["ViewCount"].ToString();
                    Response.Write("document.write(\"" + count + "\")");//很关键
    最重要的是把 ClickCount.aspx 除Page 以外的都删除掉,
    已开始就因为没有删除除Page 以外的代码,所以报错,删除后就好了。能显示结贴,人人有分,哈哈……