我做了自己的小聊天。它基本上是一个jQuery,它通过插入另一个.aspx网站来重新加载div。 这是我的.aspx网站:
<%@ Page Title="" Language="C#" MasterPageFile="~/holdOversigt.Master" AutoEventWireup="true"
CodeBehind="chat.aspx.cs" Inherits="HB.chat1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
var reloadtime = 3000;
function load() {
$.ajax({
url: "chat-Content.aspx",
context: document.body,
success: function (data) {
document.getElementById('chat').innerHTML = data;
setTimeout('load()', reloadtime);
}
});
}
window.onload = function () {
setTimeout('load()', reloadtime);
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h1 style="text-align: center; color: #005da3; font-weight: bold">
<strong>Chat rum</strong></h1>
<div id="chat" class="fisk" style="width: 500px; height: 500px">
</div>
<br />
<asp:TextBox ID="txbMessege" runat="server"></asp:TextBox>
<asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click" />
</asp:Content>
这是它插入div的网站:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="chat-Content.aspx.cs" Inherits="HB.chat_Content" %>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="lbChat" runat="server" Rows="10" Width="400px"></asp:ListBox>
</div>
</form>
这是网站代码隐藏:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace HB
{
public partial class chat_Content : System.Web.UI.Page
{
grjenie31Entities gr;
protected void Page_Load(object sender, EventArgs e)
{
gr = new grjenie31Entities();
var query = from es in gr.chats
where es.id > ((from esh in gr.chats select esh.id).Max() - 15)
orderby es.timestamps descending
select es;
List<chat> list = new List<chat>();
foreach (chat chat in query)
{
list.Add(chat);
}
for (int i = 0; i < list.Count; i++)
{
lbChat.Items.Add("[" + list[i].timestamps + "] " + list[i].personID.ToString() + ": " + list[i].besked);
}
this.lbChat.SelectedIndex = this.lbChat.Items.Count - 1;
}
}
}
我可以添加新行直到它加载...但是当站点上显示列表框时它会给我以下错误:
此页面的状态信息无效,可能已损坏。
任何人都知道我能做些什么呢?
答案 0 :(得分:0)
似乎您插入了所有页面内容甚至ViewState
隐藏标记。
我认为最好清除您的回复,并在聊天中编写您需要的html标签。
Response.Clear();
Response.ContentType = "text/plain";
Response.Write(GetChatResult());
Response.End();