分享

无刷新 切样式 同步更新未读消息数

 昵称10504424 2013-03-25

A.aspx

1
2
3
4
5
6
7
<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

1
2
3
4
5
6
7
public string getReadClass(string pIsRead)
{
    string mReturn = "";
    if (pIsRead == "False")
        mReturn = "messnoread";
    return mReturn;
}

 

D.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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

 

1
<i>(<a href="SysMessageOld.aspx" title="新消息"><asp:Label ID="lblMsgCount" runat="server"></asp:Label></a>)</i>

 

C.ascx.cs

 

1
2
3
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();
enjoy code,enjoy life.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约