静态页面是由程序动态成生的,
里面的代码是通过<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();不能显示。请高手帮忙……谢谢……
里面的代码是通过<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();不能显示。请高手帮忙……谢谢……
把统计做成脚本
内容:document.write("3232323");
<iframe src=http://localhost/.NET/NewsFiles/ClickCount.aspx?NewsId=46 frameborder="0" scrolling="no" ></iframe>测试一下效果
-------
能说得详细一点么
-------
还有就是
document.write("3232323");
对这句话不知道怎么用。
用iframe页面效果不是太好
用脚本还没弄明白,今天要搞定
string count = ds.Tables[0].Rows[0]["ViewCount"].ToString();
Response.Write("document.write(\"" + count + "\")");但访问静态新闻页面还是不显示,如果访问.aspx页面显示“document.write("88") ”,应该就是这句“Response.Write("document.write(\"" + count + "\")");”代码的问题高手指点一下吧……
string count = ds.Tables[0].Rows[0]["ViewCount"].ToString();
Response.Write("document.write(\"" + count + "\")");//很关键
最重要的是把 ClickCount.aspx 除Page 以外的都删除掉,
已开始就因为没有删除除Page 以外的代码,所以报错,删除后就好了。能显示结贴,人人有分,哈哈……