静态网页如果做到动态的评论呢和计数呢,答案:javascript的document.write()
比如计数你可以嵌入<script language="javascript" src="hit.aspx"></script>
代码如下:
hit.aspx.cs
==
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class fabu_hit : System.Web.UI.Page
{
public string Hit = null;
protected void Page_Load(object sender, EventArgs e)
{
int Id =int.Parse(Request.QueryString["id"]);
string Source = System.Configuration.ConfigurationManager.AppSettings["Source"];
SqlConnection Conn = new SqlConnection(Source);
string Sql = "update information set hit = hit +1 where id ="+Id;
SqlCommand Mycommand = new SqlCommand(Sql, Conn);
Mycommand.Connection.Open();
Mycommand.ExecuteNonQuery();
string Sql2 = "select hit from information where id=" + Id;
SqlCommand Comm = new SqlCommand(Sql2, Conn);
Hit = Comm.ExecuteScalar().ToString();
}
}
hit.aspx
==
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="hit.aspx.cs" Inherits="fabu_hit" %>
document.write(<%=Hit %>);
==
通过上面的代码可以发现就是把平常正常调用现实的用document.write()调用就可以了。ASP实现起来也是如。评论也是如此,用document.write调用表格显示即可,为了美观可以加上样式。
比如计数你可以嵌入<script language="javascript" src="hit.aspx"></script>
代码如下:
hit.aspx.cs
==
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class fabu_hit : System.Web.UI.Page
{
public string Hit = null;
protected void Page_Load(object sender, EventArgs e)
{
int Id =int.Parse(Request.QueryString["id"]);
string Source = System.Configuration.ConfigurationManager.AppSettings["Source"];
SqlConnection Conn = new SqlConnection(Source);
string Sql = "update information set hit = hit +1 where id ="+Id;
SqlCommand Mycommand = new SqlCommand(Sql, Conn);
Mycommand.Connection.Open();
Mycommand.ExecuteNonQuery();
string Sql2 = "select hit from information where id=" + Id;
SqlCommand Comm = new SqlCommand(Sql2, Conn);
Hit = Comm.ExecuteScalar().ToString();
}
}
hit.aspx
==
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="hit.aspx.cs" Inherits="fabu_hit" %>
document.write(<%=Hit %>);
==
通过上面的代码可以发现就是把平常正常调用现实的用document.write()调用就可以了。ASP实现起来也是如。评论也是如此,用document.write调用表格显示即可,为了美观可以加上样式。