A.aspx
<asp:Repeater ID="rptMessageList" runat="server"> <ItemTemplate> <tr id="trReaded_<%#Eval("RecordID")%>" class="<%#getReadClass(Eval("IsRead").ToString())%>" onclick="MarkMsgRead(<%#Eval("RecordID")%>)"> <td class="messcen_tabtd1"> <asp:CheckBox ID="chkItem" runat="server" /> <asp:Label ID="lblID" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "RecordID")%>' runat="server"></asp:Label> </td>
A.aspx
public string getReadClass(string pIsRead) { string mReturn = ""; if (pIsRead == "False") mReturn = "messnoread"; return mReturn; }
D.js
function MarkMsgRead(pRecordID) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (err1) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (err2) { xmlHttp = new XMLHttpRequest(); } } // var mUrl = "SyschangeStyle.aspx?MsgID=" + pRecordID; xmlHttp.open("GET", mUrl, true); xmlHttp.onreadystatechange = OnHandlerMsg; xmlHttp.send(null); } function OnHandlerMsg() { //0 (未初始化): (XMLHttpRequest)对象已经创建,但还没有调用open()方法。 //1 (载入):已经调用open() 方法,但尚未发送请求。 //2 (载入完成): 请求已经发送完成。 //3 (交互):可以接收到部分响应数据。 //4 (完成):已经接收到了全部数据,并且连接已经关闭。 if (xmlHttp.readyState == 4) { var isValid = xmlHttp.responseText; var mMsgCount = document.getElementById("_Header1_lblMsgCount"); mMsgCount.innerHTML = isValid.substring(isValid.indexOf(':') + 1, isValid.indexOf(']')); var mTrID = isValid.substring(0, isValid.indexOf(':')); var mTrReadID = "trReaded_" + mTrID; var exists = document.getElementById(mTrReadID); exists.removeAttribute("className"); } }
B.aspx.cs
protected void Page_Load(object sender, EventArgs e) { int msgID = int.Parse(this.Request.QueryString["MsgID"]); if (Request.QueryString["MsgID"] != null) { if (this.changeTrue(msgID)) { string customerID = myShare.GetAObject(true, 0, "CustomerID", "Customers", "UserID='" + Session["UserID"].ToString() + "'").ToString(); int ReceiverID = int.Parse(customerID); string mMsgCount; mMsgCount = myShare.GetAObject(true, 0, "count(RecordID)", "MessagesRecord", "IsRead=0 and Deleted=0 and Receiver = " + customerID).ToString(); int mmMsgCount = int.Parse(mMsgCount); Response.Write(msgID + ":" + mMsgCount + ']'); } else { Response.Write(msgID + "messnoread;修改失败"); } } else { Response.Write("请重新尝试"); } } private bool changeTrue(int pmsgID) { return myShare.SetAField(0, "IsRead", "1", "MessagesRecord", "RecordID=" + pmsgID) != null ? true : false; }
C.ascx
<i>(<a href="SysMessageOld.aspx" title="新消息"><asp:Label ID="lblMsgCount" runat="server"></asp:Label></a>)</i>
C.ascx.cs
string customerID = myShare.GetAObject(true, 0, "CustomerID", "Customers", "UserID='" + Session["UserID"].ToString() + "'").ToString(); int ReceiverID = int.Parse(customerID); lblMsgCount.Text = myShare.GetAObject(true, 0, "count(RecordID)", "MessagesRecord", "IsRead=0 and Deleted=0 and Receiver = " + customerID).ToString();