统计静态页面(新闻)访问量的问题,高手帮忙看看…………
静态页面是由程序动态成生的,
里面的代码是通过 <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());
&nb