未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 34: Session.Timeout = 1;
行 35: Application.Lock();
行 36: Application["tatol"] = (int)Application["tatol"] + 1;
行 37: Application["online"] =(int)Application["online"] + 1;
行 38: Application.UnLock();
源文件: f:\留言板\sixibook\Global.asax 行: 36 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
ASP.global_asax.Session_Start(Object sender, EventArgs e) in f:\留言板\sixibook\Global.asax:36
System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs e) +8779824
System.Web.SessionState.SessionStateModule.CompleteAcquireState() +237
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +504
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +66
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
还有一个
分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。 分析器错误消息: 服务器标记的格式不正确。源错误:
行 159: <div align="right">
行 160:
行 161: <asp:LinkButton ID="lbtnreply" runat="server" Style="position: relative" CommandArgument="<%# DataBinder.Eval(Container.DataItem,"ID","{0}") %>" OnCommand="lbtnreply_Command">回复留言</asp:LinkButton>
行 162: <asp:LinkButton ID="lbtndel" runat="server" Style="position: relative" CommandArgument="<%# DataBinder.Eval(Container.DataItem,"ID","{0}") %>" OnCommand="lbtndel_Command">删除留言</asp:LinkButton></div>
行 163: <hr />
源文件: /sixibook/index.aspx 行: 161
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.3607; ASP.NET 版本:2.0.50727.3082 谢谢各位了 我新手 用的是vs 2005
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 34: Session.Timeout = 1;
行 35: Application.Lock();
行 36: Application["tatol"] = (int)Application["tatol"] + 1;
行 37: Application["online"] =(int)Application["online"] + 1;
行 38: Application.UnLock();
源文件: f:\留言板\sixibook\Global.asax 行: 36 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
ASP.global_asax.Session_Start(Object sender, EventArgs e) in f:\留言板\sixibook\Global.asax:36
System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs e) +8779824
System.Web.SessionState.SessionStateModule.CompleteAcquireState() +237
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +504
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +66
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
还有一个
分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。 分析器错误消息: 服务器标记的格式不正确。源错误:
行 159: <div align="right">
行 160:
行 161: <asp:LinkButton ID="lbtnreply" runat="server" Style="position: relative" CommandArgument="<%# DataBinder.Eval(Container.DataItem,"ID","{0}") %>" OnCommand="lbtnreply_Command">回复留言</asp:LinkButton>
行 162: <asp:LinkButton ID="lbtndel" runat="server" Style="position: relative" CommandArgument="<%# DataBinder.Eval(Container.DataItem,"ID","{0}") %>" OnCommand="lbtndel_Command">删除留言</asp:LinkButton></div>
行 163: <hr />
源文件: /sixibook/index.aspx 行: 161
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.3607; ASP.NET 版本:2.0.50727.3082 谢谢各位了 我新手 用的是vs 2005
DataBinder.Eval(Container.DataItem, fieldname)
protected void Application_Start(object sender, EventArgs e)
{
Application["tatol"] = 0;
Application["online"] =0;
}
<%@ Register Src="gui.ascx" TagName="gui" TagPrefix="uc2" %>
<%@ Register Src="foot.ascx" TagName="foot" TagPrefix="uc3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>xuejun_200501留言板</title>
</head>
<body background="image/1.jpg">
<script type="text/javascript" >
<!--
var no = 30;
var speed = 1;
var ns4up = (document.layers) ? 1 : 0;
var ie4up = (document.all) ? 1 : 0;
var s, x, y, sn, cs;
var a, r, cx, cy;
var i, doc_width = 800, doc_height = 600;
if (ns4up) {
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
else
if (ie4up) {
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
x = new Array();
y = new Array();
r = new Array();
cx = new Array();
cy = new Array();
s = 8;
for (i = 0; i < no; ++ i) {
initRain();
if (ns4up) {
if (i == 0) {
document.write("<layer name=\"dot"+ i +"\" left=\"1\" ");
document.write("top=\"1\" visibility=\"show\"><font color=\"bule\">");
document.write("○</font></layer>");
}
else {
document.write("<layer name=\"dot"+ i +"\" left=\"1\" ");
document.write("top=\"1\" visibility=\"show\"><font color=\"black\">");
document.write("○</font></layer>");
}
}
else
if (ie4up) {
if (i == 0) {
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><font color=\"red\">");
document.write("○</font></div>");
}
else {
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 12px; LEFT: 12px;\"><font color=\"green\">");
document.write("○</font></div>");
}
}
}
function initRain() {
a = 6;
r[i] = 1;
sn = Math.sin(a);
cs = Math.cos(a);
cx[i] = Math.random() * doc_width + 1;
cy[i] = Math.random() * doc_height + 1;
x[i] = r[i] * sn + cx[i];
y[i] = cy[i];
}function makeRain() {
r[i] = 1;
cx[i] = Math.random() * doc_width + 1;
cy[i] = 1;
x[i] = r[i] * sn + cx[i];
y[i] = r[i] * cs + cy[i];
}
function updateRain() {
r[i] += s;
x[i] = r[i] * sn + cx[i];
y[i] = r[i] * cs + cy[i];
}
function raindropNS() {
for (i = 0; i < no; ++ i) {
updateRain();
if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {
makeRain();
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
document.layers["dot"+i].top = y[i];
document.layers["dot"+i].left = x[i];
}
setTimeout("raindropNS()", speed);
}
function raindropIE() {
for (i = 0; i < no; ++ i) {
updateRain();
if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {
makeRain();
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
document.all["dot"+i].style.pixelTop = y[i];
document.all["dot"+i].style.pixelLeft = x[i];
}
setTimeout("raindropIE()", speed);
}
if (ns4up) {
raindropNS();
}
else
if (ie4up) {
raindropIE();
}
-->
</script> <form id="form1" runat="server">
<div> <table style="left: 152px; position: relative; top: -23px; height: 213px; cursor: move; clear: none;">
<tr>
<td style="width: 908px; height: 116px">
<uc1:header ID="Header1" runat="server"/>
</td>
</tr>
<tr>
<td style="height: 3px; clear: none; vertical-align: top; position: relative; text-align: center;">
<uc2:gui ID="Gui1" runat="server"/>
</td>
</tr>
<tr>
<td style="height: 213px" align="center">
<asp:DataList ID="DataList1" runat="server" style="position: relative; left: 0px; top: 3px;" Height="3px" Width="762px" CellPadding="4" ForeColor="#333333" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<div align="left">
<img alt="aa" src="image/<%# DataBinder.Eval(Container.DataItem,"imageAddress","{0}") %> " />
留言者:<%# DataBinder.Eval(Container.DataItem,"userName","{0}") %>
QQ:<%# DataBinder.Eval(Container.DataItem,"QQ","{0}") %>
留言时间:<%# DataBinder.Eval(Container.DataItem,"postTime","{0:d}") %>
</div>
<div align="right">
<asp:LinkButton ID="lbtnreply" runat="server" Style="position: relative" CommandArgument="<%# DataBinder.Eval(Container.DataItem,"ID","{0}") %>" OnCommand="lbtnreply_Command">回复留言</asp:LinkButton>
<asp:LinkButton ID="lbtndel" runat="server" Style="position: relative" CommandArgument="<%# DataBinder.Eval(Container.DataItem,"ID","{0}") %>" OnCommand="lbtndel_Command">删除留言</asp:LinkButton></div>
<hr />
<font color="#3399cc">
<div align="left">
留言信息:<%# DataBinder.Eval(Container.DataItem,"Content") %>
</font>
<hr />
<font color="#cc0099">
回复信息:<%# DataBinder.Eval(Container.DataItem,"Reply") %>
</font></DIV>
</ItemTemplate>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:DataList>
<div style="z-index: 101; left: 7px; vertical-align: bottom; width: 816px;
top: 18px; height: 30px; clear: none; position: relative;">
当前页:<asp:Label ID="Label1" runat="server" Text="1"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="上一页" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="下一页" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="首页" OnClick="Button3_Click" />
<asp:Button ID="Button4" runat="server" Text="尾页" OnClick="Button4_Click" />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></div>
</td>
</tr>
<tr>
<td style="height: 8px; vertical-align: bottom; text-align: center; padding-top: 1px;">
<uc3:foot ID="Foot1" runat="server" />
</td>
</tr>
</table>
</div>
<cc1:PopupWin ID="PopupWin1" runat="server" Message="" Title="系统消息" />
</form>
</body>
</html>
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 index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["admin"] == null)//判断用户身份
{
this.PopupWin1.Message = "欢迎访问!你的身份是访客----你的IP" + Request.UserHostAddress;
}
else
{
this.PopupWin1.Message = "欢迎访问!你的身份是管理员---你的IP" + Request.UserHostAddress;
} if (!this.IsPostBack)
{
this.databindlist();//绑定数据
} }
public void databindlist()
{
int curpage = Convert.ToInt32(this.Label1.Text);
SqlConnection con = DB.createcon();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from guest order by ID DESC", con);
DataSet ds = new DataSet();
sda.Fill(ds, "guest");
System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["guest"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 5;
ps.CurrentPageIndex = curpage - 1;
this.Button1.Enabled = true;
this.Button2.Enabled = true; if (curpage == 1)
{
this.Button1.Enabled = false;
}
if (curpage == ps.PageCount)
{
this.Button2.Enabled = false;
}
this.DataList1.DataSource = ps;
this.DataList1.DataBind(); this.DataList1.DataSource = ps;
this.DataList1.DataBind();
//获取总留言条数
DB.pagecount = Convert.ToString(ps.PageCount);
SqlCommand cmd = new SqlCommand("select count(*) from guest", con);
this.Label2.Text = "总留言条数:" + Convert.ToString(cmd.ExecuteScalar()) + "条";
con.Close(); }
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) - 1);
this.databindlist();
}
protected void Button2_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) + 1);
this.databindlist();
}
protected void Button3_Click(object sender, EventArgs e)
{
this.Label1.Text = "1";
this.databindlist();
}
protected void Button4_Click(object sender, EventArgs e)
{
this.Label1.Text = DB.pagecount;
this.databindlist();
} protected void lbtnreply_Command(object sender, CommandEventArgs e)
{
if (Session["admin"] == null)
{
Response.Redirect("showmes.aspx?message=对不起!只有管理员才有权删除留言!如果你是管理员!请登陆"); }
else
{
Response.Redirect("Reply.aspx?guestID=" + e.CommandArgument);
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton lkb = (LinkButton)(e.Item.FindControl("lbtndel"));
if (lkb != null)
{
lkb.Attributes.Add("onclick", "return confirm('你是否删除留言?');");
}
} protected void lbtndel_Command(object sender, CommandEventArgs e)
{ if (Session["admin"] == null)
{
Response.Redirect("showmes.aspx?message=对不起!只有管理员才有权删除留言!如果你是管理员!请登陆"); }
else
{
SqlConnection con = DB.createcon();
con.Open();
SqlCommand cmd = new SqlCommand("delete from guest where ID=" + e.CommandArgument, con);
if (Convert.ToInt32(cmd.ExecuteNonQuery()) > 0)
{
Response.Redirect("showmes.aspx?message=删除成功");
}
else
{
Response.Redirect("showmes.aspx?message=删除失败");
}
}
}
}
--------------------------------------------------------------------------------分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。 分析器错误消息: 服务器标记的格式不正确。源错误:
行 159: <div align="right">
行 160:
行 161: <asp:LinkButton ID="lbtnreply" runat="server" Style="position: relative" CommandArgument="<%# DataBinder.Eval(Container.DataItem,"ID") %>" OnCommand="lbtnreply_Command">回复留言</asp:LinkButton>
行 162: <asp:LinkButton ID="lbtndel" runat="server" Style="position: relative" CommandArgument="<%# DataBinder.Eval(Container.DataItem,"ID") %>" OnCommand="lbtndel_Command">删除留言</asp:LinkButton></div>
行 163: <hr />
源文件: /sixibook/index.aspx 行: 161
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.3607; ASP.NET 版本:2.0.50727.3082
6楼和7楼的楼主的方法 我都试过 但是不信的啊